From owner-freebsd-audit Sun Jan 16 17:17:21 2000 Delivered-To: freebsd-audit@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 758) id 00A7015102; Sun, 16 Jan 2000 17:17:19 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by hub.freebsd.org (Postfix) with ESMTP id E2FC11CD488 for ; Sun, 16 Jan 2000 17:17:19 -0800 (PST) (envelope-from kris@hub.freebsd.org) Date: Sun, 16 Jan 2000 17:17:19 -0800 (PST) From: Kris Kennaway To: audit@freebsd.org Subject: groff tempfile handling Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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