summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/fgetln.c
diff options
context:
space:
mode:
authorpfg <pfg@FreeBSD.org>2016-02-15 18:14:21 +0000
committerpfg <pfg@FreeBSD.org>2016-02-15 18:14:21 +0000
commita8c26531339041b2d4aadb7c36bb26448c2208ea (patch)
treee8e60b057212f0ae068623d5443b3b1a5dff7d6d /lib/libc/stdio/fgetln.c
parent9e195f526633140954739dd689d6fce887df68dd (diff)
downloadFreeBSD-src-a8c26531339041b2d4aadb7c36bb26448c2208ea.zip
FreeBSD-src-a8c26531339041b2d4aadb7c36bb26448c2208ea.tar.gz
getln: We cannot expand the buffer beyond INT_MAX.
In such cases return ENOMEM. This is a limitation of our implementation, alternatively you may consider getline(3). Differential Revision: https://reviews.freebsd.org/D442 (Partial) Obtained from: Apple Inc. (Libc 997.90.3) Relnotes: yes
Diffstat (limited to 'lib/libc/stdio/fgetln.c')
-rw-r--r--lib/libc/stdio/fgetln.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/libc/stdio/fgetln.c b/lib/libc/stdio/fgetln.c
index 1779de2..1509bc8 100644
--- a/lib/libc/stdio/fgetln.c
+++ b/lib/libc/stdio/fgetln.c
@@ -37,6 +37,8 @@ static char sccsid[] = "@(#)fgetln.c 8.2 (Berkeley) 1/2/94";
__FBSDID("$FreeBSD$");
#include "namespace.h"
+#include <errno.h>
+#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -61,6 +63,10 @@ __slbexpand(FILE *fp, size_t newsize)
#endif
if (fp->_lb._size >= newsize)
return (0);
+ if (newsize > INT_MAX) {
+ errno = ENOMEM;
+ return (-1);
+ }
if ((p = realloc(fp->_lb._base, newsize)) == NULL)
return (-1);
fp->_lb._base = p;
@@ -152,13 +158,14 @@ fgetln(FILE *fp, size_t *lenp)
}
*lenp = len;
#ifdef notdef
- fp->_lb._base[len] = 0;
+ fp->_lb._base[len] = '\0';
#endif
FUNLOCKFILE(fp);
return ((char *)fp->_lb._base);
error:
*lenp = 0; /* ??? */
+ fp->_flags |= __SERR;
FUNLOCKFILE(fp);
return (NULL); /* ??? */
}
OpenPOWER on IntegriCloud