Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 16 Jan 2000 17:17:19 -0800 (PST)
From:      Kris Kennaway <kris@hub.freebsd.org>
To:        audit@freebsd.org
Subject:   groff tempfile handling
Message-ID:  <Pine.BSF.4.21.0001161711490.18027-100000@hub.freebsd.org>

next in thread | raw e-mail | index | archive | help
Index: indxbib.cc
===================================================================
RCS file: /home/ncvs/src/contrib/groff/indxbib/indxbib.cc,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 indxbib.cc
--- indxbib.cc	1996/09/07 16:18:10	1.1.1.1
+++ indxbib.cc	2000/01/17 01:15:59
@@ -37,11 +37,11 @@
 
 extern "C" {
   // Sun's stdlib.h fails to declare this.
-  char *mktemp(char *);
+  int mkstemp(char *);
 }
 
 #define DEFAULT_HASH_TABLE_SIZE 997
-#define TEMP_INDEX_TEMPLATE "indxbibXXXXXX"
+#define TEMP_INDEX_TEMPLATE "indxbibXXXXXXXXXX"
 
 // (2^n - MALLOC_OVERHEAD) should be a good argument for malloc().
 
@@ -126,7 +126,7 @@
   parser_t parser = do_file;
   const char *directory = 0;
   const char *foption = 0;
-  int opt;
+  int opt, fd;
   while ((opt = getopt(argc, argv, "c:o:h:i:k:l:t:n:c:d:f:vw")) != EOF)
     switch (opt) {
     case 'c':
@@ -217,14 +217,14 @@
     strcpy(temp_index_file + (p - basename), TEMP_INDEX_TEMPLATE);
   }
   else {
-    temp_index_file = strsave(TEMP_INDEX_TEMPLATE);
+    if((temp_index_file = strsave(TEMP_INDEX_TEMPLATE)) == NULL)
+      fatal("can't create temporary file name");
   }
-  if (!mktemp(temp_index_file) || !temp_index_file[0])
-    fatal("cannot create file name for temporary file");
   catch_fatal_signals();
-  int fd = creat(temp_index_file, S_IRUSR|S_IRGRP|S_IROTH);
-  if (fd < 0)
+  if ((fd = mkstemp(temp_index_file)) < 0)
     fatal("can't create temporary index file: %1", strerror(errno));
+  if (fchmod(fd, S_IRUSR|S_IRGRP|S_IROTH) < 0)
+    fatal("can't change permissions on temporary file");
   indxfp = fdopen(fd, "w");
   if (indxfp == 0)
     fatal("fdopen failed");

----
"How many roads must a man walk down, before you call him a man?"
"Eight!"
"That was a rhetorical question!"
"Oh..then, seven!" -- Homer Simpson



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-audit" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0001161711490.18027-100000>