summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>2016-08-25 19:55:31 +0000
committerache <ache@FreeBSD.org>2016-08-25 19:55:31 +0000
commitfc5cb9894ea57b7b3eeb9fad1fc2557483fbc65c (patch)
tree6475baa75f24fc132a13fd572682d64f4e2ac9e8 /lib
parentc29dc2b4296960868edafe94ebf975be284200bb (diff)
downloadFreeBSD-src-fc5cb9894ea57b7b3eeb9fad1fc2557483fbc65c.zip
FreeBSD-src-fc5cb9894ea57b7b3eeb9fad1fc2557483fbc65c.tar.gz
MFC r295632
getln: We cannot expand the buffer beyond INT_MAX (_size overflows). 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)
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/stdio/fgetln.35
-rw-r--r--lib/libc/stdio/fgetln.c8
2 files changed, 11 insertions, 2 deletions
diff --git a/lib/libc/stdio/fgetln.3 b/lib/libc/stdio/fgetln.3
index 4b83664..7d4b89a5 100644
--- a/lib/libc/stdio/fgetln.3
+++ b/lib/libc/stdio/fgetln.3
@@ -28,7 +28,7 @@
.\" @(#)fgetln.3 8.3 (Berkeley) 4/19/94
.\" $FreeBSD$
.\"
-.Dd April 19, 1994
+.Dd February 15, 2016
.Dt FGETLN 3
.Os
.Sh NAME
@@ -97,6 +97,9 @@ These changes are lost as soon as the pointer becomes invalid.
The argument
.Fa stream
is not a stream open for reading.
+.It Bq Er ENOMEM
+The internal line buffer could not be expanded due to lack of available memory,
+or because it would need to expand beyond INT_MAX in size.
.El
.Pp
The
diff --git a/lib/libc/stdio/fgetln.c b/lib/libc/stdio/fgetln.c
index 6546768..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,7 +158,7 @@ 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);
OpenPOWER on IntegriCloud