| @@ -1,79 +1,83 @@ | | | @@ -1,79 +1,83 @@ |
1 | $NetBSD: patch-ac,v 1.1 2008/06/01 21:46:37 dholland Exp $ | | 1 | $NetBSD: patch-ac,v 1.2 2013/02/22 21:20:28 jperkin Exp $ |
2 | | | 2 | |
3 | --- uulib/uunconc.c.orig 2004-03-01 17:52:27.000000000 -0500 | | 3 | --- uulib/uunconc.c.orig 2004-03-01 22:52:27.000000000 +0000 |
4 | +++ uulib/uunconc.c 2008-06-01 17:05:57.000000000 -0400 | | 4 | +++ uulib/uunconc.c |
5 | @@ -49,6 +49,7 @@ | | 5 | @@ -49,6 +49,11 @@ |
6 | #include <errno.h> | | 6 | #include <errno.h> |
7 | #endif | | 7 | #endif |
8 | | | 8 | |
| | | 9 | +#ifdef __sun |
| | | 10 | +#define _PATH_TMP "/tmp/" |
| | | 11 | +#else |
9 | +#include <paths.h> | | 12 | +#include <paths.h> |
| | | 13 | +#endif |
10 | #include <crc32.h> | | 14 | #include <crc32.h> |
11 | #include <uudeview.h> | | 15 | #include <uudeview.h> |
12 | #include <uuint.h> | | 16 | #include <uuint.h> |
13 | @@ -1306,6 +1307,7 @@ | | 17 | @@ -1306,6 +1311,7 @@ UUDecode (uulist *data) |
14 | { | | 18 | { |
15 | int state=BEGIN, part=-1, res=0, hb; | | 19 | int state=BEGIN, part=-1, res=0, hb; |
16 | long rsize, dsize, numbytes; | | 20 | long rsize, dsize, numbytes; |
17 | + int dataoutfd; | | 21 | + int dataoutfd; |
18 | FILE *datain, *dataout; | | 22 | FILE *datain, *dataout; |
19 | unsigned char r[8]; | | 23 | unsigned char r[8]; |
20 | char *mode, *ntmp; | | 24 | char *mode, *ntmp; |
21 | @@ -1329,13 +1331,13 @@ | | 25 | @@ -1329,13 +1335,13 @@ UUDecode (uulist *data) |
22 | else | | 26 | else |
23 | mode = "wb"; /* otherwise in binary */ | | 27 | mode = "wb"; /* otherwise in binary */ |
24 | | | 28 | |
25 | - if ((data->binfile = tempnam (NULL, "uu")) == NULL) { | | 29 | - if ((data->binfile = tempnam (NULL, "uu")) == NULL) { |
26 | + if ((data->binfile = strdup (_PATH_TMP "uu.XXXXXX")) == NULL) { | | 30 | + if ((data->binfile = strdup (_PATH_TMP "uu.XXXXXX")) == NULL) { |
27 | UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, | | 31 | UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, |
28 | uustring (S_NO_TEMP_NAME)); | | 32 | uustring (S_NO_TEMP_NAME)); |
29 | return UURET_NOMEM; | | 33 | return UURET_NOMEM; |
30 | } | | 34 | } |
31 | | | 35 | |
32 | - if ((dataout = fopen (data->binfile, mode)) == NULL) { | | 36 | - if ((dataout = fopen (data->binfile, mode)) == NULL) { |
33 | + if ((dataoutfd = mkstemp (data->binfile)) < 0) { | | 37 | + if ((dataoutfd = mkstemp (data->binfile)) < 0) { |
34 | /* | | 38 | /* |
35 | * we couldn't create a temporary file. Usually this means that TMP | | 39 | * we couldn't create a temporary file. Usually this means that TMP |
36 | * and TEMP aren't set | | 40 | * and TEMP aren't set |
37 | @@ -1348,6 +1350,19 @@ | | 41 | @@ -1348,6 +1354,19 @@ UUDecode (uulist *data) |
38 | uu_errno = errno; | | 42 | uu_errno = errno; |
39 | return UURET_IOERR; | | 43 | return UURET_IOERR; |
40 | } | | 44 | } |
41 | + | | 45 | + |
42 | + /* file now safely exists, reopen it using the right mode */ | | 46 | + /* file now safely exists, reopen it using the right mode */ |
43 | + close (dataoutfd); | | 47 | + close (dataoutfd); |
44 | + if ((dataout = fopen (data->binfile, mode)) < 0) { | | 48 | + if ((dataout = fopen (data->binfile, mode)) < 0) { |
45 | + UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, | | 49 | + UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, |
46 | + uustring (S_WR_ERR_TARGET), | | 50 | + uustring (S_WR_ERR_TARGET), |
47 | + data->binfile, strerror (uu_errno = errno)); | | 51 | + data->binfile, strerror (uu_errno = errno)); |
48 | + _FP_free (data->binfile); | | 52 | + _FP_free (data->binfile); |
49 | + data->binfile = NULL; | | 53 | + data->binfile = NULL; |
50 | + uu_errno = errno; | | 54 | + uu_errno = errno; |
51 | + return UURET_IOERR; | | 55 | + return UURET_IOERR; |
52 | + } | | 56 | + } |
53 | + | | 57 | + |
54 | /* | | 58 | /* |
55 | * we don't have begin lines in Base64 or plain text files. | | 59 | * we don't have begin lines in Base64 or plain text files. |
56 | */ | | 60 | */ |
57 | @@ -1496,7 +1511,7 @@ | | 61 | @@ -1496,7 +1515,7 @@ UUDecode (uulist *data) |
58 | */ | | 62 | */ |
59 | | | 63 | |
60 | if (data->uudet == BH_ENCODED && data->binfile) { | | 64 | if (data->uudet == BH_ENCODED && data->binfile) { |
61 | - if ((ntmp = tempnam (NULL, "uu")) == NULL) { | | 65 | - if ((ntmp = tempnam (NULL, "uu")) == NULL) { |
62 | + if ((ntmp = strdup (_PATH_TMP "uu.XXXXXX")) == NULL) { | | 66 | + if ((ntmp = strdup (_PATH_TMP "uu.XXXXXX")) == NULL) { |
63 | UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, | | 67 | UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, |
64 | uustring (S_NO_TEMP_NAME)); | | 68 | uustring (S_NO_TEMP_NAME)); |
65 | progress.action = 0; | | 69 | progress.action = 0; |
66 | @@ -1510,6 +1525,17 @@ | | 70 | @@ -1510,6 +1529,17 @@ UUDecode (uulist *data) |
67 | free (ntmp); | | 71 | free (ntmp); |
68 | return UURET_IOERR; | | 72 | return UURET_IOERR; |
69 | } | | 73 | } |
70 | + if ((dataoutfd = mkstemp (ntmp)) < 0) { | | 74 | + if ((dataoutfd = mkstemp (ntmp)) < 0) { |
71 | + UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, | | 75 | + UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, |
72 | + uustring (S_NOT_OPEN_TARGET), | | 76 | + uustring (S_NOT_OPEN_TARGET), |
73 | + ntmp, strerror (uu_errno = errno)); | | 77 | + ntmp, strerror (uu_errno = errno)); |
74 | + progress.action = 0; | | 78 | + progress.action = 0; |
75 | + fclose (datain); | | 79 | + fclose (datain); |
76 | + free (ntmp); | | 80 | + free (ntmp); |
77 | + return UURET_IOERR; | | 81 | + return UURET_IOERR; |
78 | + } | | 82 | + } |
79 | + /* file now safely exists; reopen it with the right mode */ | | 83 | + /* file now safely exists; reopen it with the right mode */ |