From 8575cc9f24e25bfdba4a990506dd4dc4d3c20fef Mon Sep 17 00:00:00 2001 From: gad Date: Sun, 15 Jul 2001 04:10:32 +0000 Subject: Replace a call to 'alloca', thus avoiding an error when compiling on freebsd/alpha with -ansi (and on some non-fbsd platforms). This change can only affect the access checking of 'lpr -r'. MFC after: 1 week --- usr.sbin/lpr/lpr/lpr.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/usr.sbin/lpr/lpr/lpr.c b/usr.sbin/lpr/lpr/lpr.c index 143d98a..9610b18 100644 --- a/usr.sbin/lpr/lpr/lpr.c +++ b/usr.sbin/lpr/lpr/lpr.c @@ -698,9 +698,9 @@ static int test(const char *file) { struct exec execb; - char *path; - register int fd; - register char *cp; + size_t dlen; + int fd; + char *cp, *dirpath; if (access(file, 4) < 0) { printf("%s: cannot access %s\n", progname, file); @@ -732,6 +732,11 @@ test(const char *file) } (void) close(fd); if (rflag) { + /* + * aside: note that 'cp' is technically a 'const char *' + * (because it points into 'file'), even though strrchr + * returns a value of type 'char *'. + */ if ((cp = strrchr(file, '/')) == NULL) { if (checkwriteperm(file,".") == 0) return(1); @@ -739,11 +744,12 @@ test(const char *file) if (cp == file) { fd = checkwriteperm(file,"/"); } else { - path = alloca(strlen(file) + 1); - strcpy(path,file); - *cp = '\0'; - fd = checkwriteperm(path,file); - *cp = '/'; + /* strlcpy will change the '/' to '\0' */ + dlen = cp - file + 1; + dirpath = malloc(dlen); + strlcpy(dirpath, file, dlen); + fd = checkwriteperm(file, dirpath); + free(dirpath); } if (fd == 0) return(1); -- cgit v1.1