aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKartik Naik <kartik@bugqore.com>2026-06-25 22:00:26 +0530
committerKartik Naik <kartik@bugqore.com>2026-06-25 22:00:26 +0530
commit9c3856146a75ac038ffa8e2c089965bb91720236 (patch)
treebefed5502b96d4b852c8045585378d83691a7fbb
parentdfd60ca03d078effa4769d0bda655c959c7b2374 (diff)
downloadportable-9c3856146a75ac038ffa8e2c089965bb91720236.tar.gz
portable-9c3856146a75ac038ffa8e2c089965bb91720236.tar.bz2
portable-9c3856146a75ac038ffa8e2c089965bb91720236.zip
fix out-of-bounds write in getdelim on undersized buffer
-rw-r--r--crypto/compat/getdelim.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/crypto/compat/getdelim.c b/crypto/compat/getdelim.c
index caec3f2..2c5a8a0 100644
--- a/crypto/compat/getdelim.c
+++ b/crypto/compat/getdelim.c
@@ -38,10 +38,18 @@ getdelim(char **buf, size_t *bufsiz, int delimiter, FILE *fp)
38 char *ptr, *eptr; 38 char *ptr, *eptr;
39 39
40 40
41 if (*buf == NULL || *bufsiz == 0) { 41 /*
42 *bufsiz = BUFSIZ; 42 * Ensure the buffer can hold at least one byte plus the NUL
43 if ((*buf = malloc(*bufsiz)) == NULL) 43 * terminator before the loop writes to it. A caller-supplied
44 * buffer smaller than that is grown rather than overrun.
45 */
46 if (*buf == NULL || *bufsiz < 2) {
47 char *nbuf;
48 size_t nbufsiz = BUFSIZ;
49 if ((nbuf = realloc(*buf, nbufsiz)) == NULL)
44 return -1; 50 return -1;
51 *buf = nbuf;
52 *bufsiz = nbufsiz;
45 } 53 }
46 54
47 for (ptr = *buf, eptr = *buf + *bufsiz;;) { 55 for (ptr = *buf, eptr = *buf + *bufsiz;;) {