Fix issues with premature socket closing

master
Nick Krichevsky 2018-09-10 00:09:28 -04:00
parent 99b4c6cf88
commit b8b244679f
2 changed files with 13 additions and 1 deletions

View File

@ -233,6 +233,12 @@ enum socket_result get_all_remote_parts(int socket_fd, enum socket_type type, st
}
write_offset = current_result_size;
}
// If we never got a blank line, the message never finished.
if (!have_blank_line) {
free(buffer);
free(result);
return RESULT_MALFORMED;
}
struct socket_read_info read_info = get_read_info(message->headers);
char *body_result;
if (read_info.strategy == STRATEGY_UNDEFINED) {

View File

@ -13,7 +13,12 @@
bool running = true;
void handle_signal(int signal) {
running = false;
if (signal == SIGPIPE) {
return;
}
if (signal == SIGINT || signal == SIGTERM) {
running = false;
}
}
int main(int argc, char* argv[]) {
@ -30,6 +35,7 @@ int main(int argc, char* argv[]) {
sigemptyset(&sa.sa_mask);
sigaction(SIGINT, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);
sigaction(SIGPIPE, &sa, NULL);
struct server_info info = setup(port_num);
if (info.status == STATUS_ERROR) {