aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKartik Naik <kartik@bugqore.com>2026-07-07 13:59:07 +0530
committerKartik Naik <kartik@bugqore.com>2026-07-07 13:59:07 +0530
commit35a02a13a4013abfa7df0bd099a257bd4943da5f (patch)
tree9f91dee6e494da43e5b0e18ed2a036e6a97825a4
parent6b74040d32897e59cdf4beeb4f9cd6e054226f53 (diff)
downloadportable-35a02a13a4013abfa7df0bd099a257bd4943da5f.tar.gz
portable-35a02a13a4013abfa7df0bd099a257bd4943da5f.tar.bz2
portable-35a02a13a4013abfa7df0bd099a257bd4943da5f.zip
guard getdelim buffer growth against size_t overflow
-rw-r--r--crypto/compat/getdelim.c6
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;