connectd: pass correct buflen to memmem

After the first iteration of the loop, we call memmem with a buflen that
points past the end of buf.

In practice we probably never read the uninitialized memory since we
guarantee the buffer ends with "\r\n", and since most/all libc
implementations probably read the haystack sequentially. But maybe
there's some libc with a crazy optimization out there. It's good to use
an accurate buflen just in case.

Discovered this while running some unit tests with MSan.
This commit is contained in:
Matt Morehouse 2023-04-20 17:18:15 -05:00 committed by Rusty Russell
parent 782c17996e
commit f382ec0452

View File

@ -109,6 +109,7 @@ static const char *get_http_hdr(const tal_t *ctx, const u8 *buf, size_t buflen,
&& buf[strlen(hdrname)] == ':')
break;
buf = end + 2;
buflen -= hdrlen + 2;
}
buf += strlen(hdrname) + 1;