aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2019-04-16 11:07:37 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2019-04-16 11:07:37 +0200
commitd0ae4103ddca21b7b765347611a9cf33f0cccd74 (patch)
tree5e38377bac5b35b436dc3a6af20254e596a5a757
parentff36bec49b2a1e398a5d7731a7049662f5c1b4ec (diff)
downloadbusybox-w32-d0ae4103ddca21b7b765347611a9cf33f0cccd74.tar.gz
busybox-w32-d0ae4103ddca21b7b765347611a9cf33f0cccd74.tar.bz2
busybox-w32-d0ae4103ddca21b7b765347611a9cf33f0cccd74.zip
httpd: fix handling of EOF in get_line()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/httpd.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/networking/httpd.c b/networking/httpd.c
index 50e832c1f..53be500d3 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -1194,7 +1194,8 @@ static void send_headers_and_exit(int responseNum)
1194} 1194}
1195 1195
1196/* 1196/*
1197 * Read from the socket until '\n' or EOF. '\r' chars are removed. 1197 * Read from the socket until '\n' or EOF.
1198 * '\r' chars are removed.
1198 * '\n' is replaced with NUL. 1199 * '\n' is replaced with NUL.
1199 * Return number of characters read or 0 if nothing is read 1200 * Return number of characters read or 0 if nothing is read
1200 * ('\r' and '\n' are not counted). 1201 * ('\r' and '\n' are not counted).
@@ -1202,29 +1203,30 @@ static void send_headers_and_exit(int responseNum)
1202 */ 1203 */
1203static int get_line(void) 1204static int get_line(void)
1204{ 1205{
1205 int count = 0; 1206 int count;
1206 char c; 1207 char c;
1207 1208
1208 alarm(HEADER_READ_TIMEOUT); 1209 alarm(HEADER_READ_TIMEOUT);
1210 count = 0;
1209 while (1) { 1211 while (1) {
1210 if (hdr_cnt <= 0) { 1212 if (hdr_cnt <= 0) {
1211 hdr_cnt = safe_read(STDIN_FILENO, hdr_buf, sizeof_hdr_buf); 1213 hdr_cnt = safe_read(STDIN_FILENO, hdr_buf, sizeof_hdr_buf);
1212 if (hdr_cnt <= 0) 1214 if (hdr_cnt <= 0)
1213 break; 1215 goto ret;
1214 hdr_ptr = hdr_buf; 1216 hdr_ptr = hdr_buf;
1215 } 1217 }
1216 iobuf[count] = c = *hdr_ptr++;
1217 hdr_cnt--; 1218 hdr_cnt--;
1218 1219 c = *hdr_ptr++;
1219 if (c == '\r') 1220 if (c == '\r')
1220 continue; 1221 continue;
1221 if (c == '\n') { 1222 if (c == '\n')
1222 iobuf[count] = '\0';
1223 break; 1223 break;
1224 } 1224 iobuf[count] = c;
1225 if (count < (IOBUF_SIZE - 1)) /* check overflow */ 1225 if (count < (IOBUF_SIZE - 1)) /* check overflow */
1226 count++; 1226 count++;
1227 } 1227 }
1228 ret:
1229 iobuf[count] = '\0';
1228 return count; 1230 return count;
1229} 1231}
1230 1232