summaryrefslogtreecommitdiffstats
path: root/usr.bin/patch/util.c
diff options
context:
space:
mode:
authorespie <espie@openbsd.org>2005-05-16 15:22:46 +0000
committerespie <espie@openbsd.org>2005-05-16 15:22:46 +0000
commita6dfabdaf3b05339c1127747778b7c5117a0b905 (patch)
tree45dc328673fdc53bdfe80f55e38b843b131c3594 /usr.bin/patch/util.c
parentMention no more PT_[GS]ETFPREGS on m88k. (diff)
downloadwireguard-openbsd-a6dfabdaf3b05339c1127747778b7c5117a0b905.tar.xz
wireguard-openbsd-a6dfabdaf3b05339c1127747778b7c5117a0b905.zip
Do not call out mkdir -p, but reuse the code from mkdir(1).
Removes the possibility of nasty stuff happening thanks to unquoted arguments in system(1). Also plug a small memory leak. Problems noticed by Lionel Fourquaud. okay millert@, deraadt@
Diffstat (limited to 'usr.bin/patch/util.c')
-rw-r--r--usr.bin/patch/util.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/usr.bin/patch/util.c b/usr.bin/patch/util.c
index d34ba182ade..cb3b2f02f07 100644
--- a/usr.bin/patch/util.c
+++ b/usr.bin/patch/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.29 2004/11/19 20:00:57 otto Exp $ */
+/* $OpenBSD: util.c,v 1.30 2005/05/16 15:22:46 espie Exp $ */
/*
* patch - a program to apply diffs to original files
@@ -27,7 +27,7 @@
*/
#ifndef lint
-static const char rcsid[] = "$OpenBSD: util.c,v 1.29 2004/11/19 20:00:57 otto Exp $";
+static const char rcsid[] = "$OpenBSD: util.c,v 1.30 2005/05/16 15:22:46 espie Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -49,7 +49,6 @@ static const char rcsid[] = "$OpenBSD: util.c,v 1.29 2004/11/19 20:00:57 otto Ex
#include "backupfile.h"
#include "pathnames.h"
-
/* Rename a file, copying it if necessary. */
int
@@ -308,6 +307,7 @@ void
makedirs(const char *filename, bool striplast)
{
char *tmpbuf;
+ mode_t mode, dir_mode;
if ((tmpbuf = strdup(filename)) == NULL)
fatal("out of memory\n");
@@ -318,12 +318,11 @@ makedirs(const char *filename, bool striplast)
return; /* nothing to be done */
*s = '\0';
}
- if (snprintf(buf, sizeof(buf), "%s -p %s", _PATH_MKDIR, tmpbuf)
- >= sizeof(buf))
- fatal("buffer too small to hold %.20s...\n", tmpbuf);
-
- if (system(buf))
- pfatal("%.40s failed", buf);
+ mode = 0777 & ~umask(0);
+ dir_mode = mode | S_IWUSR | S_IXUSR;
+ if (mkpath(tmpbuf, mode, dir_mode) != 0)
+ pfatal("creation of %s failed", tmpbuf);
+ free(tmpbuf);
}
/*