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 | |
parent | d6334707f40f35832c67d20f35ad3ee6eded9654 (diff) |
a few more overflows gone
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/patch/backupfile.c | 6 | ||||
-rw-r--r-- | usr.bin/patch/util.c | 59 |
2 files changed, 22 insertions, 43 deletions
diff --git a/usr.bin/patch/backupfile.c b/usr.bin/patch/backupfile.c index c7aeb51214d..c23ef037cfe 100644 --- a/usr.bin/patch/backupfile.c +++ b/usr.bin/patch/backupfile.c @@ -1,4 +1,4 @@ -/* $OpenBSD: backupfile.c,v 1.6 1999/01/03 05:33:48 millert Exp $ */ +/* $OpenBSD: backupfile.c,v 1.7 1999/12/04 21:00:03 provos Exp $ */ /* backupfile.c -- make Emacs style backup file names Copyright (C) 1990 Free Software Foundation, Inc. @@ -14,7 +14,7 @@ Some algorithms adapted from GNU Emacs. */ #ifndef lint -static char rcsid[] = "$OpenBSD: backupfile.c,v 1.6 1999/01/03 05:33:48 millert Exp $"; +static char rcsid[] = "$OpenBSD: backupfile.c,v 1.7 1999/12/04 21:00:03 provos Exp $"; #endif /* not lint */ #include <stdio.h> @@ -195,7 +195,7 @@ concat (str1, str2) char *str1, *str2; { char *newstr; - char str1_length = strlen (str1); + int str1_length = strlen (str1); newstr = malloc (str1_length + strlen (str2) + 1); if (newstr == 0) 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. */ |