diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2019-06-07 09:14:41 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2019-06-07 09:14:41 +0200 |
commit | ed042010dc8f6e2a5e1f06db1123b7472bfbf377 (patch) | |
tree | 5f45aab9c90babe8169046edaecc071ff5a8164c | |
parent | 45e3967c20b5020bf720b9497592e231104398f3 (diff) | |
download | busybox-w32-ed042010dc8f6e2a5e1f06db1123b7472bfbf377.tar.gz busybox-w32-ed042010dc8f6e2a5e1f06db1123b7472bfbf377.tar.bz2 busybox-w32-ed042010dc8f6e2a5e1f06db1123b7472bfbf377.zip |
lpd: avoid SEGVing on immediate EOF from peer
Patch by Luís Marques <luismarques@lowrisc.org>
function old new delta
lpd_main 749 757 +8
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | printutils/lpd.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/printutils/lpd.c b/printutils/lpd.c index ce5944026..e48feef90 100644 --- a/printutils/lpd.c +++ b/printutils/lpd.c | |||
@@ -133,6 +133,8 @@ int lpd_main(int argc UNUSED_PARAM, char *argv[]) | |||
133 | 133 | ||
134 | // read command | 134 | // read command |
135 | s = queue = xmalloc_read_stdin(); | 135 | s = queue = xmalloc_read_stdin(); |
136 | if (!s) // eof? | ||
137 | return EXIT_FAILURE; | ||
136 | // we understand only "receive job" command | 138 | // we understand only "receive job" command |
137 | if (2 != *queue) { | 139 | if (2 != *queue) { |
138 | unsupported_cmd: | 140 | unsupported_cmd: |
@@ -204,7 +206,7 @@ int lpd_main(int argc UNUSED_PARAM, char *argv[]) | |||
204 | } | 206 | } |
205 | 207 | ||
206 | // validate input. | 208 | // validate input. |
207 | // we understand only "control file" or "data file" cmds | 209 | // we understand only "control file" or "data file" subcmds |
208 | if (2 != s[0] && 3 != s[0]) | 210 | if (2 != s[0] && 3 != s[0]) |
209 | goto unsupported_cmd; | 211 | goto unsupported_cmd; |
210 | if (spooling & (1 << (s[0]-1))) { | 212 | if (spooling & (1 << (s[0]-1))) { |
@@ -291,7 +293,7 @@ int lpd_main(int argc UNUSED_PARAM, char *argv[]) | |||
291 | err_exit: | 293 | err_exit: |
292 | // don't keep corrupted files | 294 | // don't keep corrupted files |
293 | if (spooling) { | 295 | if (spooling) { |
294 | #define i spooling | 296 | int i; |
295 | for (i = 2; --i >= 0; ) | 297 | for (i = 2; --i >= 0; ) |
296 | if (filenames[i]) | 298 | if (filenames[i]) |
297 | unlink(filenames[i]); | 299 | unlink(filenames[i]); |