$NetBSD: patch-ac,v 1.2 2013/02/22 21:20:28 jperkin Exp $ --- uulib/uunconc.c.orig 2004-03-01 22:52:27.000000000 +0000 +++ uulib/uunconc.c @@ -49,6 +49,11 @@ #include #endif +#ifdef __sun +#define _PATH_TMP "/tmp/" +#else +#include +#endif #include #include #include @@ -1306,6 +1311,7 @@ UUDecode (uulist *data) { int state=BEGIN, part=-1, res=0, hb; long rsize, dsize, numbytes; + int dataoutfd; FILE *datain, *dataout; unsigned char r[8]; char *mode, *ntmp; @@ -1329,13 +1335,13 @@ UUDecode (uulist *data) else mode = "wb"; /* otherwise in binary */ - if ((data->binfile = tempnam (NULL, "uu")) == NULL) { + if ((data->binfile = strdup (_PATH_TMP "uu.XXXXXX")) == NULL) { UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, uustring (S_NO_TEMP_NAME)); return UURET_NOMEM; } - if ((dataout = fopen (data->binfile, mode)) == NULL) { + if ((dataoutfd = mkstemp (data->binfile)) < 0) { /* * we couldn't create a temporary file. Usually this means that TMP * and TEMP aren't set @@ -1348,6 +1354,19 @@ UUDecode (uulist *data) uu_errno = errno; return UURET_IOERR; } + + /* file now safely exists, reopen it using the right mode */ + close (dataoutfd); + if ((dataout = fopen (data->binfile, mode)) < 0) { + UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, + uustring (S_WR_ERR_TARGET), + data->binfile, strerror (uu_errno = errno)); + _FP_free (data->binfile); + data->binfile = NULL; + uu_errno = errno; + return UURET_IOERR; + } + /* * we don't have begin lines in Base64 or plain text files. */ @@ -1496,7 +1515,7 @@ UUDecode (uulist *data) */ if (data->uudet == BH_ENCODED && data->binfile) { - if ((ntmp = tempnam (NULL, "uu")) == NULL) { + if ((ntmp = strdup (_PATH_TMP "uu.XXXXXX")) == NULL) { UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, uustring (S_NO_TEMP_NAME)); progress.action = 0; @@ -1510,6 +1529,17 @@ UUDecode (uulist *data) free (ntmp); return UURET_IOERR; } + if ((dataoutfd = mkstemp (ntmp)) < 0) { + UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, + uustring (S_NOT_OPEN_TARGET), + ntmp, strerror (uu_errno = errno)); + progress.action = 0; + fclose (datain); + free (ntmp); + return UURET_IOERR; + } + /* file now safely exists; reopen it with the right mode */ + close (dataoutfd); if ((dataout = fopen (ntmp, "wb")) == NULL) { UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, uustring (S_NOT_OPEN_TARGET),