diff options
author | Niels Provos <provos@cvs.openbsd.org> | 1999-12-04 21:00:04 +0000 |
---|---|---|
committer | Niels Provos <provos@cvs.openbsd.org> | 1999-12-04 21:00:04 +0000 |
commit | 98bf50895dc6888f98803fc9164f595e7ea98b96 (patch) | |
tree | 08cbc3fe140683e9bb5d342a78891bf80807f47a /usr.bin/patch/util.c | |
parent | d6334707f40f35832c67d20f35ad3ee6eded9654 (diff) |
a few more overflows gone
Diffstat (limited to 'usr.bin/patch/util.c')
-rw-r--r-- | usr.bin/patch/util.c | 59 |
1 files changed, 19 insertions, 40 deletions
diff --git a/usr.bin/patch/util.c b/usr.bin/patch/util.c index cc735bb7f9b..4ddb1a7cb98 100644 --- a/usr.bin/patch/util.c +++ b/usr.bin/patch/util.c @@ -1,7 +1,7 @@ -/* $OpenBSD: util.c,v 1.8 1999/12/04 01:04:14 provos Exp $ */ +/* $OpenBSD: util.c,v 1.9 1999/12/04 21:00:03 provos Exp $ */ #ifndef lint -static char rcsid[] = "$OpenBSD: util.c,v 1.8 1999/12/04 01:04:14 provos Exp $"; +static char rcsid[] = "$OpenBSD: util.c,v 1.9 1999/12/04 21:00:03 provos Exp $"; #endif /* not lint */ #include "EXTERN.h" @@ -328,45 +328,24 @@ makedirs(filename,striplast) Reg1 char *filename; bool striplast; { - char tmpbuf[256]; - Reg2 char *s = tmpbuf; - char *dirv[20]; /* Point to the NULs between elements. */ - Reg3 int i; - Reg4 int dirvp = 0; /* Number of finished entries in dirv. */ - - /* Copy `filename' into `tmpbuf' with a NUL instead of a slash - between the directories. */ - while (*filename) { - if (*filename == '/') { - filename++; - dirv[dirvp++] = s; - *s++ = '\0'; - } - else { - *s++ = *filename++; - } - } - *s = '\0'; - dirv[dirvp] = s; - if (striplast) - dirvp--; - if (dirvp < 0) - return; - - strcpy(buf, "mkdir"); - s = buf; - for (i=0; i<=dirvp; i++) { - struct stat sbuf; - - if (stat(tmpbuf, &sbuf) && errno == ENOENT) { - while (*s) s++; - *s++ = ' '; - strcpy(s, tmpbuf); - } - *dirv[i] = '/'; + char *tmpbuf; + + if ((tmpbuf = strdup(filename)) == NULL) + fatal1("out of memory\n"); + + if (striplast) { + char *s = strrchr(tmpbuf, '/'); + if (s == NULL) + return; /* nothing to be done */ + *s = '\0'; } - if (s != buf) - system(buf); + + strcpy(buf, "/bin/mkdir -p "); + if (strlcat(buf, tmpbuf, sizeof(buf)) >= sizeof(buf)) + fatal2("buffer too small to hold %.20s...\n", tmpbuf); + + if (system(buf)) + pfatal2("%.40s failed", buf); } /* Make filenames more reasonable. */ |