Module Name:    src
Committed By:   bouyer
Date:           Sun May  8 17:26:14 UTC 2011

Modified Files:
        src/lib/libc/db/btree [netbsd-4]: bt_open.c
        src/lib/libc/db/hash [netbsd-4]: hash_page.c

Log Message:
Pull up following revision(s) (requested by christos in ticket #1428):
        lib/libc/db/hash/hash_page.c: revision 1.24
        lib/libc/db/btree/bt_open.c: revision 1.25
Correct check for snprintf() overflow via Maksymilian Arciemowicz from FreeBSD.
(the bt one was ok, but set errno and make it the same for consistency).
[to be pulled up]


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.20.2.1 src/lib/libc/db/btree/bt_open.c
cvs rdiff -u -r1.19 -r1.19.2.1 src/lib/libc/db/hash/hash_page.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/db/btree/bt_open.c
diff -u src/lib/libc/db/btree/bt_open.c:1.20 src/lib/libc/db/btree/bt_open.c:1.20.2.1
--- src/lib/libc/db/btree/bt_open.c:1.20	Fri Nov  3 20:18:49 2006
+++ src/lib/libc/db/btree/bt_open.c	Sun May  8 17:26:13 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: bt_open.c,v 1.20 2006/11/03 20:18:49 christos Exp $	*/
+/*	$NetBSD: bt_open.c,v 1.20.2.1 2011/05/08 17:26:13 bouyer Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993, 1994
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)bt_open.c	8.10 (Berkeley) 8/17/94";
 #else
-__RCSID("$NetBSD: bt_open.c,v 1.20 2006/11/03 20:18:49 christos Exp $");
+__RCSID("$NetBSD: bt_open.c,v 1.20.2.1 2011/05/08 17:26:13 bouyer Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -394,7 +394,7 @@
 tmp()
 {
 	sigset_t set, oset;
-	size_t len;
+	int len;
 	int fd;
 	char *envtmp;
 	char path[PATH_MAX];
@@ -406,8 +406,10 @@
 
 	len = snprintf(path,
 	    sizeof(path), "%s/bt.XXXXXX", envtmp ? envtmp : _PATH_TMP);
-	if (len >= sizeof(path))
+	if (len < 0 || (size_t)len >= sizeof(path)) {
+		errno = ENAMETOOLONG;
 		return -1;
+	}
 	
 	(void)sigfillset(&set);
 	(void)sigprocmask(SIG_BLOCK, &set, &oset);

Index: src/lib/libc/db/hash/hash_page.c
diff -u src/lib/libc/db/hash/hash_page.c:1.19 src/lib/libc/db/hash/hash_page.c:1.19.2.1
--- src/lib/libc/db/hash/hash_page.c:1.19	Fri Nov  3 20:18:49 2006
+++ src/lib/libc/db/hash/hash_page.c	Sun May  8 17:26:13 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: hash_page.c,v 1.19 2006/11/03 20:18:49 christos Exp $	*/
+/*	$NetBSD: hash_page.c,v 1.19.2.1 2011/05/08 17:26:13 bouyer Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993, 1994
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)hash_page.c	8.7 (Berkeley) 8/16/94";
 #else
-__RCSID("$NetBSD: hash_page.c,v 1.19 2006/11/03 20:18:49 christos Exp $");
+__RCSID("$NetBSD: hash_page.c,v 1.19.2.1 2011/05/08 17:26:13 bouyer Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -880,15 +880,19 @@
 	sigset_t set, oset;
 	char *envtmp;
 	char namestr[PATH_MAX];
+	int len;
 
 	if (issetugid())
 		envtmp = NULL;
 	else
 		envtmp = getenv("TMPDIR");
 
-	if (-1 == snprintf(namestr, sizeof(namestr), "%s/_hashXXXXXX",
-	    envtmp ? envtmp : _PATH_TMP))
+	len = snprintf(namestr, sizeof(namestr), "%s/_hashXXXXXX",
+	    envtmp ? envtmp : _PATH_TMP);
+	if (len < 0 || (size_t)len >= sizeof(namestr)) {
+		errno = ENAMETOOLONG;
 		return -1;
+	}
 
 	/* Block signals; make sure file goes away at process exit. */
 	(void)sigfillset(&set);

Reply via email to