Fixed mg_parse_header to allow NULL strings

This commit is contained in:
Sergey Lyubka 2014-01-13 21:31:18 +00:00
parent bf6fc3262f
commit 472e198d4a

View File

@ -2986,10 +2986,10 @@ int parse_header(const char *str, int str_len, const char *var_name, char *buf,
int ch = ' ', len = 0, n = strlen(var_name); int ch = ' ', len = 0, n = strlen(var_name);
const char *p, *end = str + str_len, *s = NULL; const char *p, *end = str + str_len, *s = NULL;
if (buf != NULL) buf[0] = '\0'; if (buf != NULL && buf_size > 0) buf[0] = '\0';
// Find where variable starts // Find where variable starts
for (s = str; s != NULL && &s[n] < end; s++) { for (s = str; s != NULL && s + n < end; s++) {
if ((s == str || s[-1] == ' ') && s[n] == '=' && if ((s == str || s[-1] == ' ') && s[n] == '=' &&
!memcmp(s, var_name, n)) break; !memcmp(s, var_name, n)) break;
} }
@ -3014,9 +3014,9 @@ int parse_header(const char *str, int str_len, const char *var_name, char *buf,
return len; return len;
} }
int mg_parse_header(const char *str, const char *var_name, char *buf, int mg_parse_header(const char *s, const char *var_name, char *buf,
size_t buf_size) { size_t buf_size) {
return parse_header(str, strlen(str), var_name, buf, buf_size); return parse_header(s, s == NULL ? 0 : strlen(s), var_name, buf, buf_size);
} }
#ifdef USE_LUA #ifdef USE_LUA
@ -3426,7 +3426,7 @@ static void process_request(struct connection *conn) {
&conn->mg_conn); &conn->mg_conn);
} }
DBG(("%p %d %d", conn, conn->request_len, io->len)); DBG(("%p %d %d [%.*s]", conn, conn->request_len, io->len, io->len, io->buf));
if (conn->request_len < 0 || if (conn->request_len < 0 ||
(conn->request_len > 0 && !is_valid_uri(conn->mg_conn.uri))) { (conn->request_len > 0 && !is_valid_uri(conn->mg_conn.uri))) {
send_http_error(conn, 400, NULL); send_http_error(conn, 400, NULL);