diff options
| author | Theo Buehler <tb@openbsd.org> | 2026-07-07 11:12:01 +0200 |
|---|---|---|
| committer | Theo Buehler <tb@openbsd.org> | 2026-07-07 11:12:01 +0200 |
| commit | b98f3b47a34fde75c64e0ed914bb82dae8bbfc5c (patch) | |
| tree | 9f91dee6e494da43e5b0e18ed2a036e6a97825a4 | |
| parent | 6b74040d32897e59cdf4beeb4f9cd6e054226f53 (diff) | |
| parent | 35a02a13a4013abfa7df0bd099a257bd4943da5f (diff) | |
| download | portable-b98f3b47a34fde75c64e0ed914bb82dae8bbfc5c.tar.gz portable-b98f3b47a34fde75c64e0ed914bb82dae8bbfc5c.tar.bz2 portable-b98f3b47a34fde75c64e0ed914bb82dae8bbfc5c.zip | |
Land #1314 - guard getdelim against size_t overflow
| -rw-r--r-- | crypto/compat/getdelim.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/crypto/compat/getdelim.c b/crypto/compat/getdelim.c index 9bacf0c..bf4889f 100644 --- a/crypto/compat/getdelim.c +++ b/crypto/compat/getdelim.c | |||
| @@ -27,6 +27,8 @@ | |||
| 27 | * POSSIBILITY OF SUCH DAMAGE. | 27 | * POSSIBILITY OF SUCH DAMAGE. |
| 28 | */ | 28 | */ |
| 29 | 29 | ||
| 30 | #include <errno.h> | ||
| 31 | #include <stdint.h> | ||
| 30 | #include <stdio.h> | 32 | #include <stdio.h> |
| 31 | #include <stdlib.h> | 33 | #include <stdlib.h> |
| 32 | 34 | ||
| @@ -66,6 +68,10 @@ getdelim(char **buf, size_t *bufsiz, int delimiter, FILE *fp) | |||
| 66 | } | 68 | } |
| 67 | if (ptr + 2 >= eptr) { | 69 | if (ptr + 2 >= eptr) { |
| 68 | ssize_t d = ptr - *buf; | 70 | ssize_t d = ptr - *buf; |
| 71 | if (*bufsiz > SIZE_MAX / 2) { | ||
| 72 | errno = EOVERFLOW; | ||
| 73 | return -1; | ||
| 74 | } | ||
| 69 | nbufsiz = *bufsiz * 2; | 75 | nbufsiz = *bufsiz * 2; |
| 70 | if ((nbuf = realloc(*buf, nbufsiz)) == NULL) | 76 | if ((nbuf = realloc(*buf, nbufsiz)) == NULL) |
| 71 | return -1; | 77 | return -1; |
