summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgad <gad@FreeBSD.org>2001-07-15 04:10:32 +0000
committergad <gad@FreeBSD.org>2001-07-15 04:10:32 +0000
commit8575cc9f24e25bfdba4a990506dd4dc4d3c20fef (patch)
treedf6f03c4bec1a94f389b5abfb2c522302e54dff6
parentb28eadc43332d8a3f6699840db362d56f75d63c1 (diff)
downloadFreeBSD-src-8575cc9f24e25bfdba4a990506dd4dc4d3c20fef.zip
FreeBSD-src-8575cc9f24e25bfdba4a990506dd4dc4d3c20fef.tar.gz
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
-rw-r--r--usr.sbin/lpr/lpr/lpr.c22
1 files 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);
OpenPOWER on IntegriCloud