diff options
| author | Garrett D'Amore <garrett@damore.org> | 2025-01-12 13:50:32 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2025-01-12 13:50:32 -0800 |
| commit | d88484cafbf973d55dc95b7edcae5064efa8bad0 (patch) | |
| tree | de5ec0325765b7e4ffddd4e88c1f75e423b0564d /src/supplemental/http/http_msg.c | |
| parent | c34abc224e572b19fb5aa1b5afc8841705485d14 (diff) | |
| download | nng-d88484cafbf973d55dc95b7edcae5064efa8bad0.tar.gz nng-d88484cafbf973d55dc95b7edcae5064efa8bad0.tar.bz2 nng-d88484cafbf973d55dc95b7edcae5064efa8bad0.zip | |
http: fix mishandling of very long headers or URIs, and mishandling of unicode
Also, nng_err is now a distinct type which might be nicer in debuggers.
Diffstat (limited to 'src/supplemental/http/http_msg.c')
| -rw-r--r-- | src/supplemental/http/http_msg.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/supplemental/http/http_msg.c b/src/supplemental/http/http_msg.c index b147c811..0cef876a 100644 --- a/src/supplemental/http/http_msg.c +++ b/src/supplemental/http/http_msg.c @@ -177,16 +177,16 @@ nni_http_res_init(nni_http_res *res) res->data.own = false; } -static int +static nng_err http_scan_line(void *vbuf, size_t n, size_t *lenp) { - size_t len; - char lc; - char *buf = vbuf; + size_t len; + char lc; + uint8_t *buf = vbuf; lc = 0; for (len = 0; len < n; len++) { - char c = buf[len]; + uint8_t c = buf[len]; if (c == '\n') { // Technically we should be receiving CRLF, but // debugging is easier with just LF, so we behave @@ -210,13 +210,17 @@ http_scan_line(void *vbuf, size_t n, size_t *lenp) return (NNG_EAGAIN); } -static int +static nng_err http_req_parse_line(nng_http *conn, void *line) { char *method; char *uri; char *version; + if (nni_http_get_status(conn) >= NNG_HTTP_STATUS_BAD_REQUEST) { + // we've already failed it, nothing else for us to do + return (0); + } method = line; if ((uri = strchr(method, ' ')) == NULL) { nni_http_set_status(conn, NNG_HTTP_STATUS_BAD_REQUEST, NULL); @@ -248,7 +252,7 @@ http_req_parse_line(nng_http *conn, void *line) return (nni_http_set_uri(conn, uri, NULL)); } -static int +static nng_err http_res_parse_line(nng_http *conn, uint8_t *line) { char *reason; @@ -317,7 +321,7 @@ nni_http_req_parse(nng_http *conn, void *buf, size_t n, size_t *lenp) } } - if (rv == 0) { + if (rv != NNG_EAGAIN) { req->data.parsed = false; } *lenp = len; |
