diff options
| author | Kartik Naik <kartik@bugqore.com> | 2026-06-25 22:00:26 +0530 |
|---|---|---|
| committer | Kartik Naik <kartik@bugqore.com> | 2026-06-25 22:00:26 +0530 |
| commit | 9c3856146a75ac038ffa8e2c089965bb91720236 (patch) | |
| tree | befed5502b96d4b852c8045585378d83691a7fbb | |
| parent | dfd60ca03d078effa4769d0bda655c959c7b2374 (diff) | |
| download | portable-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.c | 14 |
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;;) { |
