httpd: fix handling of EOF in get_line()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
ff36bec49b
commit
d0ae4103dd
@ -1194,7 +1194,8 @@ static void send_headers_and_exit(int responseNum)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read from the socket until '\n' or EOF. '\r' chars are removed.
|
* Read from the socket until '\n' or EOF.
|
||||||
|
* '\r' chars are removed.
|
||||||
* '\n' is replaced with NUL.
|
* '\n' is replaced with NUL.
|
||||||
* Return number of characters read or 0 if nothing is read
|
* Return number of characters read or 0 if nothing is read
|
||||||
* ('\r' and '\n' are not counted).
|
* ('\r' and '\n' are not counted).
|
||||||
@ -1202,29 +1203,30 @@ static void send_headers_and_exit(int responseNum)
|
|||||||
*/
|
*/
|
||||||
static int get_line(void)
|
static int get_line(void)
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count;
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
alarm(HEADER_READ_TIMEOUT);
|
alarm(HEADER_READ_TIMEOUT);
|
||||||
|
count = 0;
|
||||||
while (1) {
|
while (1) {
|
||||||
if (hdr_cnt <= 0) {
|
if (hdr_cnt <= 0) {
|
||||||
hdr_cnt = safe_read(STDIN_FILENO, hdr_buf, sizeof_hdr_buf);
|
hdr_cnt = safe_read(STDIN_FILENO, hdr_buf, sizeof_hdr_buf);
|
||||||
if (hdr_cnt <= 0)
|
if (hdr_cnt <= 0)
|
||||||
break;
|
goto ret;
|
||||||
hdr_ptr = hdr_buf;
|
hdr_ptr = hdr_buf;
|
||||||
}
|
}
|
||||||
iobuf[count] = c = *hdr_ptr++;
|
|
||||||
hdr_cnt--;
|
hdr_cnt--;
|
||||||
|
c = *hdr_ptr++;
|
||||||
if (c == '\r')
|
if (c == '\r')
|
||||||
continue;
|
continue;
|
||||||
if (c == '\n') {
|
if (c == '\n')
|
||||||
iobuf[count] = '\0';
|
|
||||||
break;
|
break;
|
||||||
}
|
iobuf[count] = c;
|
||||||
if (count < (IOBUF_SIZE - 1)) /* check overflow */
|
if (count < (IOBUF_SIZE - 1)) /* check overflow */
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
ret:
|
||||||
|
iobuf[count] = '\0';
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user