]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: tools: make fgets_from_mem() stop at the end of the input
authorWilly Tarreau <w@1wt.eu>
Sun, 11 Aug 2024 12:44:28 +0000 (14:44 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 11 Aug 2024 12:44:28 +0000 (14:44 +0200)
The memchr() used to look for the LF character must consider the end of
input, not just the output buffer size.

This was found by oss-fuzz:
   https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=71096

No backport is needed.

src/tools.c

index 220f3fec25b00ae504615fe2b1bed91d675f2a70..15756c880bd4afa19ccefdcd74bf9d833ef93d75 100644 (file)
@@ -6681,6 +6681,9 @@ char *fgets_from_mem(char* buf, int size, const char **position, const char *end
                return NULL;
 
        size--; /* keep fgets behaviour, reads at most one less than size */
+       if (size > end - *position)
+               size = end - *position;
+
        new_pos = memchr(*position, '\n', size);
        if (new_pos) {
                /* '+1' to grab and copy '\n' at the end of line */