summaryrefslogtreecommitdiffstats
path: root/usr.sbin/lpr
diff options
context:
space:
mode:
authorgad <gad@FreeBSD.org>2001-07-22 07:25:27 +0000
committergad <gad@FreeBSD.org>2001-07-22 07:25:27 +0000
commit1e08944f4656d7bd3b8da07536111cc3aac330eb (patch)
treef9e0ff51825cce4ee1035c59b1b60338ca388b60 /usr.sbin/lpr
parentcaf592b72e15f59512403d219d57a444b4c4874e (diff)
downloadFreeBSD-src-1e08944f4656d7bd3b8da07536111cc3aac330eb.zip
FreeBSD-src-1e08944f4656d7bd3b8da07536111cc3aac330eb.tar.gz
Replace calls to strncpy with calls to strlcpy, and remove the extra step
needed to ensure that the result is null-terminated when using strncpy(). MFC after: 8 days
Diffstat (limited to 'usr.sbin/lpr')
-rw-r--r--usr.sbin/lpr/common_source/displayq.c9
-rw-r--r--usr.sbin/lpr/lpd/printjob.c43
-rw-r--r--usr.sbin/lpr/lpd/recvjob.c10
3 files changed, 25 insertions, 37 deletions
diff --git a/usr.sbin/lpr/common_source/displayq.c b/usr.sbin/lpr/common_source/displayq.c
index c4233c5..7727306 100644
--- a/usr.sbin/lpr/common_source/displayq.c
+++ b/usr.sbin/lpr/common_source/displayq.c
@@ -337,8 +337,7 @@ inform(const struct printer *pp, char *cf)
if (line[0] < 'a' || line[0] > 'z')
break;
if (copycnt == 0 || strcmp(file, line+1) != 0) {
- strncpy(file, line + 1, sizeof(file) - 1);
- file[sizeof(file) - 1] = '\0';
+ strlcpy(file, line + 1, sizeof(file));
}
copycnt++;
/*
@@ -348,8 +347,7 @@ inform(const struct printer *pp, char *cf)
*/
continue;
case 'N':
- strncpy(savedname, line + 1, sizeof(savedname) - 1);
- savedname[sizeof(savedname) - 1] = '\0';
+ strlcpy(savedname, line + 1, sizeof(savedname));
break;
}
if ((file[0] != '\0') && (savedname[0] != '\0')) {
@@ -364,8 +362,7 @@ inform(const struct printer *pp, char *cf)
if (file[0] != '\0') {
if (savedname[0] == '\0') {
/* a safeguard in case the N-ame line is missing */
- strncpy(savedname, file, sizeof(savedname) - 1);
- savedname[sizeof(savedname) - 1] = '\0';
+ strlcpy(savedname, file, sizeof(savedname));
}
show(savedname, file, copycnt);
}
diff --git a/usr.sbin/lpr/lpd/printjob.c b/usr.sbin/lpr/lpd/printjob.c
index e2ce3ea..55af7a8 100644
--- a/usr.sbin/lpr/lpd/printjob.c
+++ b/usr.sbin/lpr/lpd/printjob.c
@@ -431,14 +431,12 @@ printit(struct printer *pp, char *file)
case 'H':
strlcpy(origin_host, line + 1, sizeof(origin_host));
if (class[0] == '\0') {
- strncpy(class, line+1, sizeof(class) - 1);
- class[sizeof(class) - 1] = '\0';
+ strlcpy(class, line+1, sizeof(class));
}
continue;
case 'P':
- strncpy(logname, line+1, sizeof(logname) - 1);
- logname[sizeof(logname) - 1] = '\0';
+ strlcpy(logname, line + 1, sizeof(logname));
if (pp->restricted) { /* restricted */
if (getpwnam(logname) == NULL) {
bombed = NOACCT;
@@ -463,23 +461,24 @@ printit(struct printer *pp, char *file)
case 'J':
if (line[1] != '\0') {
- strncpy(jobname, line+1, sizeof(jobname) - 1);
- jobname[sizeof(jobname) - 1] = '\0';
+ strlcpy(jobname, line + 1, sizeof(jobname));
} else
strcpy(jobname, " ");
continue;
case 'C':
if (line[1] != '\0')
- strncpy(class, line+1, sizeof(class) - 1);
- else if (class[0] == '\0')
+ strlcpy(class, line + 1, sizeof(class));
+ else if (class[0] == '\0') {
+ /* XXX - why call gethostname instead of
+ * just strlcpy'ing local_host? */
gethostname(class, sizeof(class));
- class[sizeof(class) - 1] = '\0';
+ class[sizeof(class) - 1] = '\0';
+ }
continue;
case 'T': /* header title for pr */
- strncpy(title, line+1, sizeof(title) - 1);
- title[sizeof(title) - 1] = '\0';
+ strlcpy(title, line + 1, sizeof(title));
continue;
case 'L': /* identification line */
@@ -492,24 +491,21 @@ printit(struct printer *pp, char *file)
case '3':
case '4':
if (line[1] != '\0') {
- strncpy(fonts[line[0]-'1'], line+1,
- 50-1);
- fonts[line[0]-'1'][50-1] = '\0';
+ strlcpy(fonts[line[0]-'1'], line + 1,
+ (size_t)50);
}
continue;
case 'W': /* page width */
- strncpy(width+2, line+1, sizeof(width) - 3);
- width[2+sizeof(width) - 3] = '\0';
+ strlcpy(width+2, line + 1, sizeof(width) - 2);
continue;
case 'I': /* indent amount */
- strncpy(indent+2, line+1, sizeof(indent) - 3);
- indent[2+sizeof(indent) - 3] = '\0';
+ strlcpy(indent+2, line + 1, sizeof(indent) - 2);
continue;
case 'Z': /* locale for pr */
- strncpy(locale, line+1, sizeof(locale) - 1);
+ strlcpy(locale, line + 1, sizeof(locale));
locale[sizeof(locale) - 1] = '\0';
continue;
@@ -896,12 +892,10 @@ sendit(struct printer *pp, char *file)
} else if (line[0] == 'H') {
strlcpy(origin_host, line + 1, sizeof(origin_host));
if (class[0] == '\0') {
- strncpy(class, line+1, sizeof(class) - 1);
- class[sizeof(class) - 1] = '\0';
+ strlcpy(class, line + 1, sizeof(class));
}
} else if (line[0] == 'P') {
- strncpy(logname, line+1, sizeof(logname) - 1);
- logname[sizeof(logname) - 1] = '\0';
+ strlcpy(logname, line + 1, sizeof(logname));
if (pp->restricted) { /* restricted */
if (getpwnam(logname) == NULL) {
sendmail(pp, line+1, NOACCT);
@@ -910,8 +904,7 @@ sendit(struct printer *pp, char *file)
}
}
} else if (line[0] == 'I') {
- strncpy(indent+2, line+1, sizeof(indent) - 3);
- indent[2 + sizeof(indent) - 3] = '\0';
+ strlcpy(indent+2, line + 1, sizeof(indent) - 2);
} else if (line[0] >= 'a' && line[0] <= 'z') {
strcpy(last, line);
while ((i = getline(cfp)) != 0)
diff --git a/usr.sbin/lpr/lpd/recvjob.c b/usr.sbin/lpr/lpd/recvjob.c
index d473680..dbc948a 100644
--- a/usr.sbin/lpr/lpd/recvjob.c
+++ b/usr.sbin/lpr/lpd/recvjob.c
@@ -191,10 +191,9 @@ readjob(struct printer *pp)
* something different than what gethostbyaddr()
* returns
*/
- strncpy(cp + 6, from_host, sizeof(line) + line - cp
- - 7);
- line[sizeof(line) - 1 ] = '\0';
- strncpy(tfname, cp, sizeof(tfname) - 1);
+ strlcpy(cp + 6, from_host, sizeof(line)
+ + (size_t)(line - cp - 6));
+ strlcpy(tfname, cp, sizeof(tfname));
tfname[sizeof (tfname) - 1] = '\0';
tfname[0] = 't';
if (strchr(tfname, '/'))
@@ -229,8 +228,7 @@ readjob(struct printer *pp)
(void) write(STDOUT_FILENO, "\2", 1);
continue;
}
- (void) strncpy(dfname, cp, sizeof(dfname) - 1);
- dfname[sizeof(dfname) - 1] = '\0';
+ strlcpy(dfname, cp, sizeof(dfname));
if (strchr(dfname, '/')) {
frecverr("readjob: %s: illegal path name",
dfname);
OpenPOWER on IntegriCloud