hurl

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 507bbf24b497940404172a65808a0da45df54a55
parent 1e46afb6d205fa41815bbd84b63de163d7b0c341
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Mon, 12 Nov 2018 20:22:44 +0100

as suspected it was incorrect

off-by-one because of NUL termination when the buffer is fully filled.

Diffstat:
Mhurl.c | 12++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/hurl.c b/hurl.c @@ -222,14 +222,16 @@ https_request(void) /* NOTE: HTTP header must fit in the buffer */ for (len = 0; len < sizeof(buf); len += r) { - if ((r = tls_read(t, &buf[len], sizeof(buf) - len)) == 0) + /* NOTE: buffer size is -1 to NUL terminate the buffer for a + string comparison. */ + if ((r = tls_read(t, &buf[len], sizeof(buf) - len - 1)) == 0) break; if (r == -1) { fprintf(stderr, "tls_read: %s\n", tls_error(t)); goto err; } } - buf[len] = '\0'; /* XXX: correct? */ + buf[len] = '\0'; if (!strncmp(buf, "HTTP/1.0 200 ", sizeof("HTTP/1.0 200 ") - 1) || !strncmp(buf, "HTTP/1.1 200 ", sizeof("HTTP/1.1 200 ") - 1)) @@ -323,14 +325,16 @@ http_request(void) /* NOTE: HTTP header must fit in the buffer */ for (len = 0; len < sizeof(buf); len += r) { - if ((r = read(fd, &buf[len], sizeof(buf) - len)) == 0) + /* NOTE: buffer size is -1 to NUL terminate the buffer for a + string comparison. */ + if ((r = read(fd, &buf[len], sizeof(buf) - len - 1)) == 0) break; if (r == -1) { fprintf(stderr, "read: %s\n", strerror(errno)); goto err; } } - buf[len] = '\0'; /* XXX: correct? */ + buf[len] = '\0'; if (!strncmp(buf, "HTTP/1.0 200 ", sizeof("HTTP/1.0 200 ") - 1) || !strncmp(buf, "HTTP/1.1 200 ", sizeof("HTTP/1.1 200 ") - 1))