From 16bd17ce2d680932e8bbaa2fcef288c0046ea146 Mon Sep 17 00:00:00 2001 From: Kris Kennaway Date: Sun, 16 Jan 2000 21:08:58 +0000 Subject: [PATCH] Fix insecure tempfile handling Reviewed by: audit@freebsd.org --- sbin/ldconfig/ldconfig.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/sbin/ldconfig/ldconfig.c b/sbin/ldconfig/ldconfig.c index 01bbe1f5d59..07e5abcfa58 100644 --- a/sbin/ldconfig/ldconfig.c +++ b/sbin/ldconfig/ldconfig.c @@ -465,17 +465,13 @@ buildhints() errx(1, "str_index(%d) != strtab_sz(%d)", str_index, strtab_sz); } - tmpfile = concat(hints_file, ".XXXXXX", ""); - if ((tmpfile = mktemp(tmpfile)) == NULL) { + tmpfile = concat(hints_file, ".XXXXXXXXXX", ""); + umask(0); /* Create with exact permissions */ + if ((fd = mkstemp(tmpfile)) == -1) { warn("%s", tmpfile); return -1; } - - umask(0); /* Create with exact permissions */ - if ((fd = open(tmpfile, O_RDWR|O_CREAT|O_TRUNC, 0444)) == -1) { - warn("%s", hints_file); - return -1; - } + fchmod(fd, 0444); if (write(fd, &hdr, sizeof(struct hints_header)) != sizeof(struct hints_header)) {