Module Name:    src
Committed By:   seanb
Date:           Tue Jan 21 19:09:48 UTC 2014

Modified Files:
        src/lib/libc/stdio: gettemp.c

Log Message:
Handle case where a 0 length template string or a template
of all 'X' would dereference, and maybe assign to, memory
before the template.  Simplify.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/lib/libc/stdio/gettemp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/stdio/gettemp.c
diff -u src/lib/libc/stdio/gettemp.c:1.16 src/lib/libc/stdio/gettemp.c:1.17
--- src/lib/libc/stdio/gettemp.c:1.16	Mon Apr 22 20:57:36 2013
+++ src/lib/libc/stdio/gettemp.c	Tue Jan 21 19:09:48 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: gettemp.c,v 1.16 2013/04/22 20:57:36 christos Exp $	*/
+/*	$NetBSD: gettemp.c,v 1.17 2014/01/21 19:09:48 seanb Exp $	*/
 
 /*
  * Copyright (c) 1987, 1993
@@ -40,7 +40,7 @@
 #if 0
 static char sccsid[] = "@(#)mktemp.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: gettemp.c,v 1.16 2013/04/22 20:57:36 christos Exp $");
+__RCSID("$NetBSD: gettemp.c,v 1.17 2014/01/21 19:09:48 seanb Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -89,14 +89,18 @@ GETTEMP(char *path, int *doopen, int dom
 			xcnt = 0;	
 
 	/* Use at least one from xtra.  Use 2 if more than 6 X's. */
-	if (*(trv - 1) == 'X')
+	if (xcnt > 0) {
 		*--trv = xtra[0];
-	if (xcnt > 6 && *(trv - 1) == 'X')
+		xcnt--;
+	}
+	if (xcnt > 5) {
 		*--trv = xtra[1];
+		xcnt--;
+	}
 
 	/* Set remaining X's to pid digits with 0's to the left. */
-	while (*--trv == 'X') {
-		*trv = (pid % 10) + '0';
+	for (; xcnt > 0; xcnt--) {
+		*--trv = (pid % 10) + '0';
 		pid /= 10;
 	}
 

Reply via email to