summaryrefslogtreecommitdiffstats
path: root/lib/libc/db/hash/hash_page.c
diff options
context:
space:
mode:
authordelphij <delphij@FreeBSD.org>2009-03-28 05:57:27 +0000
committerdelphij <delphij@FreeBSD.org>2009-03-28 05:57:27 +0000
commit13f44a2a242d0a0c1ccb45ecb1ffdee19a0c6f8a (patch)
tree0a6801eaaefea7f6cb427376ac4bedcb2861c390 /lib/libc/db/hash/hash_page.c
parent21b00fc42b2ab16bc19a270792a72971dc10973f (diff)
downloadFreeBSD-src-13f44a2a242d0a0c1ccb45ecb1ffdee19a0c6f8a.zip
FreeBSD-src-13f44a2a242d0a0c1ccb45ecb1ffdee19a0c6f8a.tar.gz
db/btree/bt_open.c: check return value of snprintf() and return value
if the result is truncated. db/hash/hash_page.c: use the same way to create temporary file as bt_open.c; check snprintf() return value. Obtained from: OpenBSD
Diffstat (limited to 'lib/libc/db/hash/hash_page.c')
-rw-r--r--lib/libc/db/hash/hash_page.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/lib/libc/db/hash/hash_page.c b/lib/libc/db/hash/hash_page.c
index 0c01468..6ca2826 100644
--- a/lib/libc/db/hash/hash_page.c
+++ b/lib/libc/db/hash/hash_page.c
@@ -53,7 +53,7 @@ __FBSDID("$FreeBSD$");
*/
#include "namespace.h"
-#include <sys/types.h>
+#include <sys/param.h>
#include <errno.h>
#include <fcntl.h>
@@ -833,13 +833,24 @@ static int
open_temp(HTAB *hashp)
{
sigset_t set, oset;
- static char namestr[] = "_hashXXXXXX";
+ int len;
+ char *envtmp = NULL;
+ char path[MAXPATHLEN];
+
+ if (issetugid() == 0)
+ envtmp = getenv("TMPDIR");
+ len = snprintf(path,
+ sizeof(path), "%s/_hash.XXXXXX", envtmp ? envtmp : "/tmp");
+ if (len < 0 || len >= sizeof(path)) {
+ errno = ENAMETOOLONG;
+ return (-1);
+ }
/* Block signals; make sure file goes away at process exit. */
(void)sigfillset(&set);
(void)_sigprocmask(SIG_BLOCK, &set, &oset);
- if ((hashp->fp = mkstemp(namestr)) != -1) {
- (void)unlink(namestr);
+ if ((hashp->fp = mkstemp(path)) != -1) {
+ (void)unlink(path);
(void)_fcntl(hashp->fp, F_SETFD, 1);
}
(void)_sigprocmask(SIG_SETMASK, &oset, (sigset_t *)NULL);
OpenPOWER on IntegriCloud