summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1997-06-17 08:38:04 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1997-06-17 08:38:04 +0000
commitd6aaf94f9b2819683f638e9eabdf0b8a890dd71a (patch)
tree50b3e8449a29a152c70d7a2cbde86935ac0c82b6
parente0b95274df2684f64e033e5dd525cb6a2efad3b2 (diff)
use mktemp, but use it without guessability or DOS attacks
-rw-r--r--usr.sbin/pkg_install/delete/perform.c6
-rw-r--r--usr.sbin/pkg_install/lib/pen.c37
2 files changed, 25 insertions, 18 deletions
diff --git a/usr.sbin/pkg_install/delete/perform.c b/usr.sbin/pkg_install/delete/perform.c
index 06edcaad3d7..0478d86b566 100644
--- a/usr.sbin/pkg_install/delete/perform.c
+++ b/usr.sbin/pkg_install/delete/perform.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: perform.c,v 1.2 1996/06/04 08:43:38 niklas Exp $ */
+/* $OpenBSD: perform.c,v 1.3 1997/06/17 08:38:03 deraadt Exp $ */
#ifndef lint
-static const char *rcsid = "$OpenBSD: perform.c,v 1.2 1996/06/04 08:43:38 niklas Exp $";
+static const char *rcsid = "$OpenBSD: perform.c,v 1.3 1997/06/17 08:38:03 deraadt Exp $";
#endif
/*
@@ -177,7 +177,7 @@ undepend(PackingList p, char *pkgname)
whinge("Couldn't open dependency file `%s'", fname);
return;
}
- sprintf(ftmp, "%s.XXXXXX", fname);
+ sprintf(ftmp, "%s.XXXXXXXXXX", fname);
s = mkstemp(ftmp);
if (s == -1) {
fclose(fp);
diff --git a/usr.sbin/pkg_install/lib/pen.c b/usr.sbin/pkg_install/lib/pen.c
index 42c89b6e715..ca1d501595c 100644
--- a/usr.sbin/pkg_install/lib/pen.c
+++ b/usr.sbin/pkg_install/lib/pen.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: pen.c,v 1.2 1996/06/04 08:43:45 niklas Exp $ */
+/* $OpenBSD: pen.c,v 1.3 1997/06/17 08:38:03 deraadt Exp $ */
#ifndef lint
-static const char *rcsid = "$OpenBSD: pen.c,v 1.2 1996/06/04 08:43:45 niklas Exp $";
+static const char *rcsid = "$OpenBSD: pen.c,v 1.3 1997/06/17 08:38:03 deraadt Exp $";
#endif
/*
@@ -49,15 +49,15 @@ find_play_pen(char *pen, size_t sz)
if (pen[0] && stat(pen, &sb) != FAIL && (min_free(pen) >= sz))
return pen;
else if ((cp = getenv("PKG_TMPDIR")) != NULL && stat(cp, &sb) != FAIL && (min_free(cp) >= sz))
- sprintf(pen, "%s/instmp.XXXXXX", cp);
+ sprintf(pen, "%s/instmp.XXXXXXXXXX", cp);
else if ((cp = getenv("TMPDIR")) != NULL && stat(cp, &sb) != FAIL && (min_free(cp) >= sz))
- sprintf(pen, "%s/instmp.XXXXXX", cp);
+ sprintf(pen, "%s/instmp.XXXXXXXXXX", cp);
else if (stat("/var/tmp", &sb) != FAIL && min_free("/var/tmp") >= sz)
- strcpy(pen, "/var/tmp/instmp.XXXXXX");
+ strcpy(pen, "/var/tmp/instmp.XXXXXXXXXX");
else if (stat("/tmp", &sb) != FAIL && min_free("/tmp") >= sz)
- strcpy(pen, "/tmp/instmp.XXXXXX");
+ strcpy(pen, "/tmp/instmp.XXXXXXXXXX");
else if ((stat("/usr/tmp", &sb) == SUCCESS || mkdir("/usr/tmp", 01777) == SUCCESS) && min_free("/usr/tmp") >= sz)
- strcpy(pen, "/usr/tmp/instmp.XXXXXX");
+ strcpy(pen, "/usr/tmp/instmp.XXXXXXXXXX");
else {
barf("Can't find enough temporary space to extract the files, please set\n"
"your PKG_TMPDIR environment variable to a location with at least %d bytes\n"
@@ -75,18 +75,25 @@ char *
make_playpen(char *pen, size_t sz)
{
char *tmp;
+ int i = 0;
- if (!find_play_pen(pen, sz))
- return NULL;
+ while (1) {
+ if (!find_play_pen(pen, sz))
+ return NULL;
- if (!mktemp(pen)) {
- barf("Can't mktemp '%s'.", pen);
- return NULL;
- }
- if (mkdir(pen, 0755) == FAIL) {
- barf("Can't mkdir '%s'.", pen);
+ if (!mktemp(pen)) {
+ barf("Can't mktemp '%s'.", pen);
+ return NULL;
+ }
+ if (mkdir(pen, 0755) == FAIL && i++ < 100) {
+ /* try again! */
+ continue;
+ }
+
+ barf("Can't mkdir '%s'.", pen);
return NULL;
}
+
if (Verbose) {
if (sz)
fprintf(stderr, "Requested space: %d bytes, free space: %d bytes in %s\n", (int)sz, min_free(pen), pen);