aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/db/hash/hash_page.c
diff options
context:
space:
mode:
authorXin LI <delphij@FreeBSD.org>2009-03-28 05:57:27 +0000
committerXin LI <delphij@FreeBSD.org>2009-03-28 05:57:27 +0000
commit02d7f710b8ee073248b00312c6a0394ad3bac8f6 (patch)
tree0a6801eaaefea7f6cb427376ac4bedcb2861c390 /lib/libc/db/hash/hash_page.c
parentf60486b3ce5512c89a3c3f9dfc411cdec048c921 (diff)
downloadsrc-02d7f710b8ee073248b00312c6a0394ad3bac8f6.tar.gz
src-02d7f710b8ee073248b00312c6a0394ad3bac8f6.zip
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
Notes
Notes: svn path=/head/; revision=190485
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 0c0146846554..6ca28264461b 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);