as suspected it was incorrect - hurl - Gopher/HTTP/HTTPS file grabber
 (HTM) git clone git://git.codemadness.org/hurl
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 507bbf24b497940404172a65808a0da45df54a55
 (DIR) parent 1e46afb6d205fa41815bbd84b63de163d7b0c341
 (HTM) 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:
         M hurl.c                              |      12 ++++++++----
       
       1 file changed, 8 insertions(+), 4 deletions(-)
       ---
 (DIR) 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))