Date: Mon, 10 Jan 2000 00:30:42 -0800 (PST) From: Kris Kennaway <kris@hub.freebsd.org> To: audit@freebsd.org Subject: Re: Tempfile handling in kgzip Message-ID: <Pine.BSF.4.21.0001100029380.70366-100000@hub.freebsd.org> In-Reply-To: <Pine.BSF.4.21.0001090205320.87817-100000@hub.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, 9 Jan 2000, Kris Kennaway wrote:
> tempnam() -> mkstemp()
Updated patch respects TMPDIR like tempnam() does, in case anyone relied
on that.
Kris
Index: kgzip.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/kgzip/kgzip.c,v
retrieving revision 1.2
diff -u -r1.2 kgzip.c
--- kgzip.c 1999/08/28 01:16:43 1.2
+++ kgzip.c 2000/01/10 08:27:40
@@ -47,11 +47,9 @@
#define SFX_KGZ ".kgz" /* Filename suffix: executable */
#define SFX_MAX 5 /* Size of larger filename suffix */
-#define TMP_PREFIX "kgz" /* Temporary file prefix */
-
const char *loader = "/usr/lib/kgzldr.o"; /* Default loader */
-static const char *tname; /* Name of temporary file */
+char *tname; /* Name of temporary file */
static void cleanup(void);
static void mk_fn(int, const char *, const char *, char *[]);
@@ -68,6 +66,12 @@
const char *output;
int cflag, vflag, c;
+ if (getenv("TMPDIR") == NULL)
+ tname = strdup("/tmp/kgzXXXXXXXXXX");
+ else
+ if (asprintf(&tname, "%s/kgzXXXXXXXXXX", getenv("TMPDIR")) == -1)
+ errx(1, "Out of memory");
+
output = NULL;
cflag = vflag = 0;
while ((c = getopt(argc, argv, "cvl:o:")) != -1)
@@ -122,7 +126,7 @@
{
const char *p, *s;
size_t n;
- int i;
+ int i, fd;
i = 0;
s = strrchr(f1, 0);
@@ -133,8 +137,9 @@
}
fn[i++] = (char *)f1;
if (i == FN_OBJ && !cflag) {
- if (!(tname = tempnam(NULL, TMP_PREFIX)))
+ if ((fd = mkstemp(tname)) == -1)
err(1, NULL);
+ close(fd);
fn[i++] = (char *)tname;
}
if (!(fn[i] = (char *)f2)) {
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-audit" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0001100029380.70366-100000>
