Module Name: src
Committed By: christos
Date: Sun Dec 13 18:14:13 UTC 2015
Modified Files:
src/usr.sbin/sup/source: expand.c
Log Message:
PR/50547: David Binderman: fix bad sizeof
To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/usr.sbin/sup/source/expand.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.sbin/sup/source/expand.c
diff -u src/usr.sbin/sup/source/expand.c:1.18 src/usr.sbin/sup/source/expand.c:1.19
--- src/usr.sbin/sup/source/expand.c:1.18 Sat Oct 17 18:26:13 2009
+++ src/usr.sbin/sup/source/expand.c Sun Dec 13 13:14:13 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: expand.c,v 1.18 2009/10/17 22:26:13 christos Exp $ */
+/* $NetBSD: expand.c,v 1.19 2015/12/13 18:14:13 christos Exp $ */
/*
* Copyright (c) 1991 Carnegie Mellon University
@@ -78,6 +78,7 @@
static jmp_buf sjbuf;
static char pathbuf[MAXPATHLEN];
+static size_t maxpathlen;
static char *path, *pathp, *lastpathp;
static const char globchars[] = "{[*?";/* meta characters */
@@ -104,7 +105,8 @@ expand(char *spec, char **buffer, int bu
{
pathp = path = pathbuf;
*pathp = 0;
- lastpathp = &path[MAXPATHLEN - 2];
+ maxpathlen = sizeof(pathbuf) - 1;
+ lastpathp = &path[maxpathlen];
BUFFER = buffer;
BUFSIZE = bufsize;
bufcnt = 0;
@@ -131,12 +133,11 @@ glob(char *as)
if (!*cs || *cs == '/') {
if (pathp != path + 1) {
*pathp = 0;
- if (gethdir(path + 1, sizeof path - 1))
+ if (gethdir(path + 1, maxpathlen))
goto endit;
- strncpy(path, path + 1, sizeof path - 1);
+ strlcpy(path, path + 1, maxpathlen);
} else
- strncpy(path, (char *) getenv("HOME"), sizeof path - 1);
- path[sizeof path - 1] = '\0';
+ strlcpy(path, getenv("HOME"), maxpathlen);
pathp = path + strlen(path);
}
}
@@ -398,7 +399,6 @@ gethdir(char *home, size_t homelen)
if (pp == 0)
return (1);
- strncpy(home, pp->pw_dir, homelen - 1);
- home[homelen - 1] = '\0';
+ strlcpy(home, pp->pw_dir, homelen);
return (0);
}