$OpenBSD$ --- util/gifinto.c.orig 2004-02-23 20:16:55.000000000 +0100 +++ util/gifinto.c 2004-02-23 20:17:03.000000000 +0100 @@ -28,6 +28,7 @@ #include #include #include +#include #include "gif_lib.h" #include "getarg.h" @@ -73,6 +74,7 @@ int main(int argc, char **argv) { int Error, NumFiles, MinSizeFlag = FALSE, HelpFlag = FALSE; + int fd = -1; char **FileName = NULL, TmpName[80], FoutTmpName[80], FullPath[80], DefaultName[80], s[80], *p; FILE *Fin, *Fout; @@ -114,31 +116,16 @@ int main(int argc, char **argv) } #endif - /* Isolate the directory where our destination is, and set tmp file name */ - /* in the very same directory. */ - strcpy(FullPath, *FileName); - if ((p = strrchr(FullPath, '/')) != NULL || - (p = strrchr(FullPath, '\\')) != NULL) - p[1] = 0; - else if ((p = strrchr(FullPath, ':')) != NULL) - p[1] = 0; - else - FullPath[0] = 0; /* No directory or disk specified. */ - - strcpy(FoutTmpName, FullPath); /* Generate destination temporary name. */ - /* Make sure the temporary is made in the current directory: */ - p = tmpnam(TmpName); - if (strrchr(p, '/')) p = strrchr(p, '/') + 1; - if (strrchr(p, '\\')) p = strrchr(p, '\\') + 1; - if (strlen(p) == 0) p = DEFAULT_TMP_NAME; - strcat(FoutTmpName, p); - - Fout = fopen(FoutTmpName, "wb"); - if (Fout == NULL) - { - GIF_EXIT("Failed to open output."); - } - + strlcpy(FoutTmpName, "/tmp/gifinto.XXXXXXXXXX", sizeof (FoutTmpName)); + if ((fd = mkstemp(FoutTmpName)) == -1 || + (Fout = fdopen(fd, "w+")) == NULL) { + if (fd != -1) { + unlink(FoutTmpName); + close(fd); + } + GIF_EXIT("Failed to open output."); + } + #ifdef __MSDOS__ if (setvbuf(Fout, NULL, _IOFBF, GIF_FILE_BUFFER_SIZE)) /*Incr. stream buf.*/ {