summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/getdelim.c
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>2014-10-16 17:31:51 +0000
committermillert <millert@openbsd.org>2014-10-16 17:31:51 +0000
commitce95f2848165d8e6170c199e00c40fe439ebb4fc (patch)
tree8ebc0e7b755bac16286fee12ef29b73092d84cc5 /lib/libc/stdio/getdelim.c
parentRemove references to unimplemented CLOCK_VIRTUAL. It is non-standard (diff)
downloadwireguard-openbsd-ce95f2848165d8e6170c199e00c40fe439ebb4fc.tar.xz
wireguard-openbsd-ce95f2848165d8e6170c199e00c40fe439ebb4fc.zip
Fix bounds check for newlen without relying on unspecified behavior.
OK deraadt@
Diffstat (limited to 'lib/libc/stdio/getdelim.c')
-rw-r--r--lib/libc/stdio/getdelim.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/lib/libc/stdio/getdelim.c b/lib/libc/stdio/getdelim.c
index dcde0c34e61..5e583cb5552 100644
--- a/lib/libc/stdio/getdelim.c
+++ b/lib/libc/stdio/getdelim.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: getdelim.c,v 1.1 2012/03/21 23:44:35 fgsch Exp $ */
+/* $OpenBSD: getdelim.c,v 1.2 2014/10/16 17:31:51 millert Exp $ */
/* $NetBSD: getdelim.c,v 1.13 2011/07/22 23:12:30 joerg Exp $ */
/*
@@ -78,13 +78,12 @@ getdelim(char **__restrict buf, size_t *__restrict buflen,
else
len = (p - fp->_p) + 1;
- newlen = off + len;
/* Ensure we can handle it */
- if (newlen < off || newlen > SSIZE_MAX) {
+ if (off > SSIZE_MAX || len + 1 > SSIZE_MAX - off) {
errno = EOVERFLOW;
goto error;
}
- newlen++; /* reserve space for the NULL terminator */
+ newlen = off + len + 1; /* reserve space for NUL terminator */
if (newlen > *buflen) {
if (newlen < MINBUF)
newlen = MINBUF;