Index: lib/libc/stdio/fgetln.3 =================================================================== --- lib/libc/stdio/fgetln.3 +++ lib/libc/stdio/fgetln.3 @@ -28,7 +28,7 @@ .\" @(#)fgetln.3 8.3 (Berkeley) 4/19/94 .\" $FreeBSD$ .\" -.Dd April 19, 1994 +.Dd February 19, 2016 .Dt FGETLN 3 .Os .Sh NAME @@ -97,6 +97,9 @@ 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 Index: lib/libc/stdio/fgetln.c =================================================================== --- lib/libc/stdio/fgetln.c +++ lib/libc/stdio/fgetln.c @@ -37,6 +37,8 @@ __FBSDID("$FreeBSD$"); #include "namespace.h" +#include +#include #include #include #include @@ -61,6 +63,10 @@ #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; @@ -159,6 +165,7 @@ error: *lenp = 0; /* ??? */ + fp->_flags |= __SERR; FUNLOCKFILE(fp); return (NULL); /* ??? */ } Index: lib/libc/stdio/fputs.c =================================================================== --- lib/libc/stdio/fputs.c +++ lib/libc/stdio/fputs.c @@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$"); #include "namespace.h" +#include #include #include #include "un-namespace.h" @@ -62,5 +63,7 @@ ORIENT(fp, -1); retval = __sfvwrite(fp, &uio); FUNLOCKFILE(fp); + if (retval == 0) + return (iov.iov_len > INT_MAX ? INT_MAX : iov.iov_resid); return (retval); }