Thu May 19 19:46:10 2011 UTC ()
Pull up following revision(s) (requested by christos in ticket #1602):
	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]


(bouyer)
diff -r1.24 -r1.24.14.1 src/lib/libc/db/btree/bt_open.c
diff -r1.23 -r1.23.14.1 src/lib/libc/db/hash/hash_page.c

cvs diff -r1.24 -r1.24.14.1 src/lib/libc/db/btree/bt_open.c (expand / switch to unified diff)

--- src/lib/libc/db/btree/bt_open.c 2008/09/11 12:58:00 1.24
+++ src/lib/libc/db/btree/bt_open.c 2011/05/19 19:46:10 1.24.14.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: bt_open.c,v 1.24 2008/09/11 12:58:00 joerg Exp $ */ 1/* $NetBSD: bt_open.c,v 1.24.14.1 2011/05/19 19:46:10 bouyer Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1990, 1993, 1994 4 * Copyright (c) 1990, 1993, 1994
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Mike Olson. 8 * Mike Olson.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -27,27 +27,27 @@ @@ -27,27 +27,27 @@
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE. 32 * SUCH DAMAGE.
33 */ 33 */
34 34
35#if HAVE_NBTOOL_CONFIG_H 35#if HAVE_NBTOOL_CONFIG_H
36#include "nbtool_config.h" 36#include "nbtool_config.h"
37#endif 37#endif
38 38
39#include <sys/cdefs.h> 39#include <sys/cdefs.h>
40__RCSID("$NetBSD: bt_open.c,v 1.24 2008/09/11 12:58:00 joerg Exp $"); 40__RCSID("$NetBSD: bt_open.c,v 1.24.14.1 2011/05/19 19:46:10 bouyer Exp $");
41 41
42/* 42/*
43 * Implementation of btree access method for 4.4BSD. 43 * Implementation of btree access method for 4.4BSD.
44 * 44 *
45 * The design here was originally based on that of the btree access method 45 * The design here was originally based on that of the btree access method
46 * used in the Postgres database system at UC Berkeley. This implementation 46 * used in the Postgres database system at UC Berkeley. This implementation
47 * is wholly independent of the Postgres code. 47 * is wholly independent of the Postgres code.
48 */ 48 */
49 49
50#include "namespace.h" 50#include "namespace.h"
51#include <sys/stat.h> 51#include <sys/stat.h>
52 52
53#include <assert.h> 53#include <assert.h>
@@ -381,40 +381,42 @@ nroot(BTREE *t) @@ -381,40 +381,42 @@ nroot(BTREE *t)
381 root->lower = BTDATAOFF; 381 root->lower = BTDATAOFF;
382 root->upper = t->bt_psize; 382 root->upper = t->bt_psize;
383 root->flags = P_BLEAF; 383 root->flags = P_BLEAF;
384 memset(meta, 0, t->bt_psize); 384 memset(meta, 0, t->bt_psize);
385 mpool_put(t->bt_mp, meta, MPOOL_DIRTY); 385 mpool_put(t->bt_mp, meta, MPOOL_DIRTY);
386 mpool_put(t->bt_mp, root, MPOOL_DIRTY); 386 mpool_put(t->bt_mp, root, MPOOL_DIRTY);
387 return (RET_SUCCESS); 387 return (RET_SUCCESS);
388} 388}
389 389
390static int 390static int
391tmp(void) 391tmp(void)
392{ 392{
393 sigset_t set, oset; 393 sigset_t set, oset;
394 size_t len; 394 int len;
395 int fd; 395 int fd;
396 char *envtmp; 396 char *envtmp;
397 char path[PATH_MAX]; 397 char path[PATH_MAX];
398 398
399 if (issetugid()) 399 if (issetugid())
400 envtmp = NULL; 400 envtmp = NULL;
401 else 401 else
402 envtmp = getenv("TMPDIR"); 402 envtmp = getenv("TMPDIR");
403 403
404 len = snprintf(path, 404 len = snprintf(path,
405 sizeof(path), "%s/bt.XXXXXX", envtmp ? envtmp : _PATH_TMP); 405 sizeof(path), "%s/bt.XXXXXX", envtmp ? envtmp : _PATH_TMP);
406 if (len >= sizeof(path)) 406 if (len < 0 || (size_t)len >= sizeof(path)) {
 407 errno = ENAMETOOLONG;
407 return -1; 408 return -1;
 409 }
408  410
409 (void)sigfillset(&set); 411 (void)sigfillset(&set);
410 (void)sigprocmask(SIG_BLOCK, &set, &oset); 412 (void)sigprocmask(SIG_BLOCK, &set, &oset);
411 if ((fd = mkstemp(path)) != -1) { 413 if ((fd = mkstemp(path)) != -1) {
412 (void)unlink(path); 414 (void)unlink(path);
413 (void)fcntl(fd, F_SETFD, FD_CLOEXEC); 415 (void)fcntl(fd, F_SETFD, FD_CLOEXEC);
414 } 416 }
415 (void)sigprocmask(SIG_SETMASK, &oset, NULL); 417 (void)sigprocmask(SIG_SETMASK, &oset, NULL);
416 return(fd); 418 return(fd);
417} 419}
418 420
419static int 421static int
420byteorder(void) 422byteorder(void)

cvs diff -r1.23 -r1.23.14.1 src/lib/libc/db/hash/hash_page.c (expand / switch to unified diff)

--- src/lib/libc/db/hash/hash_page.c 2008/09/11 12:58:00 1.23
+++ src/lib/libc/db/hash/hash_page.c 2011/05/19 19:46:10 1.23.14.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: hash_page.c,v 1.23 2008/09/11 12:58:00 joerg Exp $ */ 1/* $NetBSD: hash_page.c,v 1.23.14.1 2011/05/19 19:46:10 bouyer Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1990, 1993, 1994 4 * Copyright (c) 1990, 1993, 1994
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Margo Seltzer. 8 * Margo Seltzer.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -27,27 +27,27 @@ @@ -27,27 +27,27 @@
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE. 32 * SUCH DAMAGE.
33 */ 33 */
34 34
35#if HAVE_NBTOOL_CONFIG_H 35#if HAVE_NBTOOL_CONFIG_H
36#include "nbtool_config.h" 36#include "nbtool_config.h"
37#endif 37#endif
38 38
39#include <sys/cdefs.h> 39#include <sys/cdefs.h>
40__RCSID("$NetBSD: hash_page.c,v 1.23 2008/09/11 12:58:00 joerg Exp $"); 40__RCSID("$NetBSD: hash_page.c,v 1.23.14.1 2011/05/19 19:46:10 bouyer Exp $");
41 41
42/* 42/*
43 * PACKAGE: hashing 43 * PACKAGE: hashing
44 * 44 *
45 * DESCRIPTION: 45 * DESCRIPTION:
46 * Page manipulation for hashing package. 46 * Page manipulation for hashing package.
47 * 47 *
48 * ROUTINES: 48 * ROUTINES:
49 * 49 *
50 * External 50 * External
51 * __get_page 51 * __get_page
52 * __add_ovflpage 52 * __add_ovflpage
53 * Internal 53 * Internal
@@ -859,35 +859,39 @@ __free_ovflpage(HTAB *hashp, BUFHEAD *ob @@ -859,35 +859,39 @@ __free_ovflpage(HTAB *hashp, BUFHEAD *ob
859} 859}
860 860
861/* 861/*
862 * Returns: 862 * Returns:
863 * 0 success 863 * 0 success
864 * -1 failure 864 * -1 failure
865 */ 865 */
866static int 866static int
867open_temp(HTAB *hashp) 867open_temp(HTAB *hashp)
868{ 868{
869 sigset_t set, oset; 869 sigset_t set, oset;
870 char *envtmp; 870 char *envtmp;
871 char namestr[PATH_MAX]; 871 char namestr[PATH_MAX];
 872 int len;
872 873
873 if (issetugid()) 874 if (issetugid())
874 envtmp = NULL; 875 envtmp = NULL;
875 else 876 else
876 envtmp = getenv("TMPDIR"); 877 envtmp = getenv("TMPDIR");
877 878
878 if (-1 == snprintf(namestr, sizeof(namestr), "%s/_hashXXXXXX", 879 len = snprintf(namestr, sizeof(namestr), "%s/_hashXXXXXX",
879 envtmp ? envtmp : _PATH_TMP)) 880 envtmp ? envtmp : _PATH_TMP);
 881 if (len < 0 || (size_t)len >= sizeof(namestr)) {
 882 errno = ENAMETOOLONG;
880 return -1; 883 return -1;
 884 }
881 885
882 /* Block signals; make sure file goes away at process exit. */ 886 /* Block signals; make sure file goes away at process exit. */
883 (void)sigfillset(&set); 887 (void)sigfillset(&set);
884 (void)sigprocmask(SIG_BLOCK, &set, &oset); 888 (void)sigprocmask(SIG_BLOCK, &set, &oset);
885 if ((hashp->fp = mkstemp(namestr)) != -1) { 889 if ((hashp->fp = mkstemp(namestr)) != -1) {
886 (void)unlink(namestr); 890 (void)unlink(namestr);
887 (void)fcntl(hashp->fp, F_SETFD, FD_CLOEXEC); 891 (void)fcntl(hashp->fp, F_SETFD, FD_CLOEXEC);
888 } 892 }
889 (void)sigprocmask(SIG_SETMASK, &oset, (sigset_t *)NULL); 893 (void)sigprocmask(SIG_SETMASK, &oset, (sigset_t *)NULL);
890 return (hashp->fp != -1 ? 0 : -1); 894 return (hashp->fp != -1 ? 0 : -1);
891} 895}
892 896
893/* 897/*