Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F177771915
D57184.1795249617.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
D57184.1795249617.diff
View Options
diff --git a/usr.sbin/lpr/lpd/printjob.c b/usr.sbin/lpr/lpd/printjob.c
--- a/usr.sbin/lpr/lpd/printjob.c
+++ b/usr.sbin/lpr/lpd/printjob.c
@@ -68,8 +68,12 @@
/*
* The buffer size to use when reading/writing spool files.
+ * This is also used to compose commands for remote servers and therefore
+ * needs to be able to fit the longest command we could possibly send.
*/
-#define SPL_BUFSIZ BUFSIZ
+#define SPL_BUFSIZ (BUFSIZ * 2)
+_Static_assert(SPL_BUFSIZ > sizeof("x18446744073709551615 ") + PATH_MAX +
+ sizeof("_c2147483647 "), "SPL_BUFSIZ is too short");
/*
* Error tokens
@@ -640,7 +644,7 @@
if (pp->filters[LPF_INPUT] == NULL
&& (format == 'f' || format == 'l' || format == 'o')) {
pp->tof = 0;
- while ((n = read(fi, buf, SPL_BUFSIZ)) > 0)
+ while ((n = read(fi, buf, sizeof(buf))) > 0)
if (write(ofd, buf, n) != n) {
(void) close(fi);
return (REPRINT);
@@ -1127,13 +1131,18 @@
sendagain:
copycnt++;
- if (copycnt < 2)
- (void) sprintf(buf, "%c%" PRId64 " %s\n", type, stb.st_size,
- file);
- else
- (void) sprintf(buf, "%c%" PRId64 " %s_c%d\n", type, stb.st_size,
- file, copycnt);
- amt = strlen(buf);
+ if (copycnt < 2) {
+ amt = snprintf(buf, sizeof(buf), "%c%" PRId64 " %s\n",
+ type, stb.st_size, file);
+ } else {
+ amt = snprintf(buf, sizeof(buf), "%c%" PRId64 " %s_c%d\n",
+ type, stb.st_size, file, copycnt);
+ }
+ if (amt >= sizeof(buf)) {
+ syslog(LOG_ERR, "%s: file name too long", file);
+ sfres = ERROR;
+ goto return_sfres;
+ }
for (i = 0; ; i++) {
if (write(pfd, buf, amt) != amt ||
(resp = response(pp)) < 0 || resp == '\1') {
@@ -1157,8 +1166,8 @@
*/
if (type == '\3')
trstat_init(pp, file, job_dfcnt);
- for (i = 0; i < stb.st_size; i += SPL_BUFSIZ) {
- amt = SPL_BUFSIZ;
+ for (i = 0; i < stb.st_size; i += sizeof(buf)) {
+ amt = sizeof(buf);
if (i + amt > stb.st_size)
amt = stb.st_size - i;
if (sizerr == 0 && read(sfd, buf, amt) != amt)
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 21, 8:26 AM (2 h, 8 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41839243
Default Alt Text
D57184.1795249617.diff (1 KB)
Attached To
Mode
D57184: lpd: Avoid buffer overflow when sending a job
Attached
Detach File
Event Timeline