summaryrefslogtreecommitdiff
path: root/lib/libc
diff options
context:
space:
mode:
authorseanb <seanb@NetBSD.org>2014-01-21 19:09:48 +0000
committerseanb <seanb@NetBSD.org>2014-01-21 19:09:48 +0000
commit4617894b85c00a4cf2a5b7f83e631ca55456a477 (patch)
tree2b69d5ca074008ae0a5897ce2fff622b2d5deee7 /lib/libc
parent8504dd1a4453fe004b7deb1251d6c6d749cf0bac (diff)
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.
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/stdio/gettemp.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/lib/libc/stdio/gettemp.c b/lib/libc/stdio/gettemp.c
index 5ee143fcf31..17f6af8394c 100644
--- a/lib/libc/stdio/gettemp.c
+++ b/lib/libc/stdio/gettemp.c
@@ -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 domkdir)
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;
}