| 1 |
From 3dbaf762329a89c445e3ff224f706a256c8f637d Mon Sep 17 00:00:00 2001 |
| 2 |
From: Stephen Paul Weber <[email protected]> |
| 3 |
Date: Wed, 18 Mar 2015 10:38:19 -0500 |
| 4 |
Subject: [PATCH 05/10] Use mkstemp |
| 5 |
|
| 6 |
special filenames is the key! |
| 7 |
--- |
| 8 |
src/core/tools.c | 29 +++++++++++++---------------- |
| 9 |
1 file changed, 13 insertions(+), 16 deletions(-) |
| 10 |
|
| 11 |
diff --git a/src/core/tools.c b/src/core/tools.c |
| 12 |
index 1a781bb..510de99 100644 |
| 13 |
--- a/src/core/tools.c |
| 14 |
+++ b/src/core/tools.c |
| 15 |
@@ -39,7 +39,7 @@ char *call_gpg_round(char *switches, char *input, char *input2, \ |
| 16 |
int get_stderr, int snip_data, unsigned round) { |
| 17 |
int pipefd[2], rwepipe[3], childpid, tmp2_fd = 0, in_data = !snip_data; |
| 18 |
FILE* cstream; |
| 19 |
- char *cmd, *tmp2_path = NULL, *output = NULL; |
| 20 |
+ char *cmd, *output = NULL; |
| 21 |
size_t output_size = 0; |
| 22 |
char buf[100], buf2[100] = ""; |
| 23 |
const char *keyid = settings_get_str("xmpp_pgp"); |
| 24 |
@@ -55,18 +55,17 @@ char *call_gpg_round(char *switches, char *input, char *input2, \ |
| 25 |
} |
| 26 |
|
| 27 |
if(input2) { /* NOTE for security it might be better if this were a named pipe */ |
| 28 |
- if(!(tmp2_path = tempnam(NULL, "irssi-xmpp-gpg"))) goto pgp_error; |
| 29 |
- if((tmp2_fd = open(tmp2_path, O_WRONLY|O_CREAT|O_EXCL, \ |
| 30 |
- S_IRUSR|S_IWUSR)) < 0) |
| 31 |
- goto pgp_error; |
| 32 |
- |
| 33 |
+ if((tmp2_fd = mkstemp("irssi-xmpp-gpgXXXXXX")) == -1) goto pgp_error; |
| 34 |
if(write(tmp2_fd, input2, strlen(input2)) < 0) goto pgp_error; |
| 35 |
} |
| 36 |
|
| 37 |
- cmd = malloc(sizeof("gpg -u '' --passphrase-fd '' --trust-model always" \ |
| 38 |
- " -qo - --batch --no-tty - ''") \ |
| 39 |
- +strlen(switches)+8+ \ |
| 40 |
- (tmp2_path ? strlen(tmp2_path) : 0)); |
| 41 |
+ cmd = malloc(sizeof("gpg --enable-special-filenames -u ''" \ |
| 42 |
+ "--passphrase-fd '' --trust-model always" \ |
| 43 |
+ " -qo - --batch --no-tty - '' -&") \ |
| 44 |
+ +1+strlen(switches)+5+ /* 5 is for passphrase-fd */ \ |
| 45 |
+ (keyid ? strlen(keyid) : 0)+ \ |
| 46 |
+ (keyid ? strlen(keyid) : 0)+ \ |
| 47 |
+ (tmp2_fd ? 5 : 0)); |
| 48 |
if(keyid) { |
| 49 |
strcpy(cmd, "gpg -u '"); |
| 50 |
strcat(cmd, keyid); |
| 51 |
@@ -78,12 +77,11 @@ char *call_gpg_round(char *switches, char *input, char *input2, \ |
| 52 |
strcpy(cmd, "gpg "); |
| 53 |
} |
| 54 |
strcat(cmd, switches); |
| 55 |
- strcat(cmd, " --trust-model always -qo - --batch --no-tty - "); |
| 56 |
+ strcat(cmd, " --enable-special-filenames --trust-model always -qo -" \ |
| 57 |
+ " --batch --no-tty - "); |
| 58 |
|
| 59 |
- if(tmp2_path) { |
| 60 |
- strcat(cmd, "'"); |
| 61 |
- strcat(cmd, tmp2_path); |
| 62 |
- strcat(cmd, "'"); |
| 63 |
+ if(tmp2_fd) { |
| 64 |
+ sprintf(cmd+strlen(cmd), "-&%d", tmp2_fd); |
| 65 |
} |
| 66 |
|
| 67 |
fflush(NULL); |
| 68 |
@@ -138,7 +136,6 @@ char *call_gpg_round(char *switches, char *input, char *input2, \ |
| 69 |
|
| 70 |
done: |
| 71 |
if(tmp2_fd) close(tmp2_fd); |
| 72 |
- if(tmp2_path) free(tmp2_path); |
| 73 |
if(keyid) close(pipefd[0]); |
| 74 |
free(cmd); |
| 75 |
|
| 76 |
-- |
| 77 |
2.1.4 |
| 78 |
|