[git commit] lpd: avoid SEGVing on immediate EOF from peer

Denys Vlasenko vda.linux at googlemail.com
Fri Jun 7 07:14:41 UTC 2019


commit: https://git.busybox.net/busybox/commit/?id=ed042010dc8f6e2a5e1f06db1123b7472bfbf377
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

Patch by Luís Marques <luismarques at lowrisc.org>

function                                             old     new   delta
lpd_main                                             749     757      +8

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 printutils/lpd.c | 6 ++++--
 1 file 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[])
 
 	// read command
 	s = queue = xmalloc_read_stdin();
+	if (!s) // eof?
+		return EXIT_FAILURE;
 	// we understand only "receive job" command
 	if (2 != *queue) {
  unsupported_cmd:
@@ -204,7 +206,7 @@ int lpd_main(int argc UNUSED_PARAM, char *argv[])
 		}
 
 		// validate input.
-		// we understand only "control file" or "data file" cmds
+		// we understand only "control file" or "data file" subcmds
 		if (2 != s[0] && 3 != s[0])
 			goto unsupported_cmd;
 		if (spooling & (1 << (s[0]-1))) {
@@ -291,7 +293,7 @@ int lpd_main(int argc UNUSED_PARAM, char *argv[])
  err_exit:
 	// don't keep corrupted files
 	if (spooling) {
-#define i spooling
+		int i;
 		for (i = 2; --i >= 0; )
 			if (filenames[i])
 				unlink(filenames[i]);


More information about the busybox-cvs mailing list