diff options
author | 1996-08-27 03:32:53 +0000 | |
---|---|---|
committer | 1996-08-27 03:32:53 +0000 | |
commit | 5160187f93f725e945f4c2c21a7bb741ea57c2cc (patch) | |
tree | 7b2b95076d989206821fef5eef1f23234c648d97 /lib/libc | |
parent | Ensure strings are NUL terminated after strncpy (diff) | |
download | wireguard-openbsd-5160187f93f725e945f4c2c21a7bb741ea57c2cc.tar.xz wireguard-openbsd-5160187f93f725e945f4c2c21a7bb741ea57c2cc.zip |
use strncpy correctly
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/net/res_init.c | 5 | ||||
-rw-r--r-- | lib/libc/net/res_query.c | 4 | ||||
-rw-r--r-- | lib/libc/rpc/getrpcent.c | 5 | ||||
-rw-r--r-- | lib/libc/time/zdump.c | 11 |
4 files changed, 16 insertions, 9 deletions
diff --git a/lib/libc/net/res_init.c b/lib/libc/net/res_init.c index c925236869e..cb60d4c0df1 100644 --- a/lib/libc/net/res_init.c +++ b/lib/libc/net/res_init.c @@ -52,7 +52,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: res_init.c,v 1.5 1996/08/25 10:11:02 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: res_init.c,v 1.6 1996/08/27 03:32:53 deraadt Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/param.h> @@ -131,6 +131,7 @@ res_init() /* Allow user to override the local domain definition */ if (issetugid() == 0 && (cp = getenv("LOCALDOMAIN")) != NULL) { (void)strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1); + _res.defdname[sizeof(_res.defdname) - 1] = '\0'; if ((cp = strpbrk(_res.defdname, " \t\n")) != NULL) *cp = '\0'; haveenv++; @@ -183,6 +184,7 @@ res_init() continue; (void)strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1); + _res.defdname[sizeof(_res.defdname) - 1] = '\0'; if ((cp = strpbrk(_res.defdname, " \t\n")) != NULL) *cp = '\0'; havesearch = 0; @@ -226,6 +228,7 @@ res_init() continue; (void)strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1); + _res.defdname[sizeof(_res.defdname) - 1] = '\0'; if ((cp = strchr(_res.defdname, '\n')) != NULL) *cp = '\0'; /* diff --git a/lib/libc/net/res_query.c b/lib/libc/net/res_query.c index 8fa987ad6b6..fb2d22c1192 100644 --- a/lib/libc/net/res_query.c +++ b/lib/libc/net/res_query.c @@ -52,7 +52,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: res_query.c,v 1.6 1996/08/24 09:32:20 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: res_query.c,v 1.7 1996/08/27 03:32:54 deraadt Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/param.h> @@ -379,8 +379,8 @@ __hostalias(name) break; for (cp2 = cp1 + 1; *cp2 && !isspace(*cp2); ++cp2) ; - abuf[sizeof(abuf) - 1] = *cp2 = '\0'; (void)strncpy(abuf, cp1, sizeof(abuf) - 1); + abuf[sizeof(abuf) - 1] = *cp2 = '\0'; fclose(fp); return (abuf); } diff --git a/lib/libc/rpc/getrpcent.c b/lib/libc/rpc/getrpcent.c index f0b0b91ae63..ab555062553 100644 --- a/lib/libc/rpc/getrpcent.c +++ b/lib/libc/rpc/getrpcent.c @@ -29,7 +29,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: getrpcent.c,v 1.3 1996/08/19 08:31:34 tholo Exp $"; +static char *rcsid = "$OpenBSD: getrpcent.c,v 1.4 1996/08/27 03:33:57 deraadt Exp $"; #endif /* LIBC_SCCS and not lint */ /* @@ -165,7 +165,8 @@ interpret(val, len) if (d == 0) return (0); - (void) strncpy(d->line, val, len); + (void) strncpy(d->line, val, len-1); + d->line[len-1] = '\0'; p = d->line; d->line[len] = '\n'; if (*p == '#') diff --git a/lib/libc/time/zdump.c b/lib/libc/time/zdump.c index 0f034b74d98..e0f76d13fac 100644 --- a/lib/libc/time/zdump.c +++ b/lib/libc/time/zdump.c @@ -1,5 +1,5 @@ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: zdump.c,v 1.2 1996/08/19 08:34:55 tholo Exp $"; +static char rcsid[] = "$OpenBSD: zdump.c,v 1.3 1996/08/27 03:36:57 deraadt Exp $"; #endif /* LIBC_SCCS and not lint */ /* @@ -189,7 +189,8 @@ char * argv[]; t += SECSPERHOUR * HOURSPERDAY; show(argv[i], t, TRUE); tm = *localtime(&t); - (void) strncpy(buf, abbr(&tm), (sizeof buf) - 1); + (void) strncpy(buf, abbr(&tm), sizeof(buf) - 1); + buf[sizeof(buf) - 1] = '\0'; for ( ; ; ) { if (cutoff != NULL && t >= cuttime) break; @@ -205,7 +206,8 @@ char * argv[]; newt = hunt(argv[i], t, newt); newtm = *localtime(&newt); (void) strncpy(buf, abbr(&newtm), - (sizeof buf) - 1); + sizeof(buf) - 1); + buf[sizeof(buf) - 1] = '\0'; } t = newt; tm = newtm; @@ -246,7 +248,8 @@ time_t hit; static char loab[MAX_STRING_LENGTH]; lotm = *localtime(&lot); - (void) strncpy(loab, abbr(&lotm), (sizeof loab) - 1); + (void) strncpy(loab, abbr(&lotm), sizeof(loab) - 1); + loab[sizeof(loab) - 1] = '\0'; while ((hit - lot) >= 2) { t = lot / 2 + hit / 2; if (t <= lot) |