about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorWilliam Wennerström <william@wstrm.dev>2020-06-28 15:45:19 +0200
committerWilliam Wennerström <william@wstrm.dev>2020-11-16 21:58:08 +0100
commit04bfa23ead26801728e0e7f2dfb5100556cefe66 (patch)
tree8bccad7a93de9f3e1f31597113cada719f97d421
parent9d58472c8cb4dd9fffc5620cae681c064e32f7bb (diff)
downloadprofani-tty-04bfa23ead26801728e0e7f2dfb5100556cefe66.tar.gz
Remove temporary ciphertext file when finished
-rw-r--r--src/command/cmd_funcs.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index 113192cc..6dcb591f 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -4862,7 +4862,8 @@ cmd_sendfile(ProfWin* window, const char* const command, gchar** args)
 
                 // Create temporary file for writing ciphertext.
                 int tmpfd;
-                if ((tmpfd = g_file_open_tmp("profanity.XXXXXX", NULL, NULL)) == -1) {
+                char *tmpname = NULL;
+                if ((tmpfd = g_file_open_tmp("profanity.XXXXXX", &tmpname, NULL)) == -1) {
                     char *msg = "Unable to create temporary file for encrypted transfer.";
                     cons_show_error(msg);
                     win_println(window, THEME_ERROR, "-", msg);
@@ -4871,6 +4872,11 @@ cmd_sendfile(ProfWin* window, const char* const command, gchar** args)
                 }
                 FILE *tmpfh = fdopen(tmpfd, "wb");
 
+                // The temporary ciphertext file should be removed upon closure
+                // later.
+                remove(tmpname);
+                free(tmpname);
+
                 int crypt_res;
                 alt_scheme = OMEMO_AESGCM_URL_SCHEME;
                 alt_fragment = omemo_encrypt_file(fh, tmpfh, file_size(fd), &crypt_res);
@@ -4889,7 +4895,7 @@ cmd_sendfile(ProfWin* window, const char* const command, gchar** args)
 
                 fclose(fh); // Also closes descriptor.
 
-                // Switch original stream with temporary encrypted stream.
+                // Switch original stream with temporary ciphertext stream.
                 fd = tmpfd;
                 fh = tmpfh;