Page MenuHomeFreeBSD

D442.id839.diff
No OneTemporary

D442.id839.diff

Index: lib/libc/stdio/fgetln.3
===================================================================
--- lib/libc/stdio/fgetln.3
+++ lib/libc/stdio/fgetln.3
@@ -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 <errno.h>
+#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -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/fpurge.c
===================================================================
--- lib/libc/stdio/fpurge.c
+++ lib/libc/stdio/fpurge.c
@@ -61,7 +61,7 @@
FREEUB(fp);
fp->_p = fp->_bf._base;
fp->_r = 0;
- fp->_w = fp->_flags & (__SLBF|__SNBF|__SRD) ? 0 : fp->_bf._size;
+ fp->_w = fp->_flags & (__SLBF|__SNBF) ? 0 : fp->_bf._size;
retval = 0;
}
FUNLOCKFILE(fp);
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 <limits.h>
#include <stdio.h>
#include <string.h>
#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_len);
return (retval);
}
Index: lib/libc/stdio/freopen.c
===================================================================
--- lib/libc/stdio/freopen.c
+++ lib/libc/stdio/freopen.c
@@ -151,6 +151,14 @@
/* Get a new descriptor to refer to the new file. */
f = _open(file, oflags, DEFFILEMODE);
+ /* If out of fd's close the old one and try again. */
+ if (f < 0 && isopen && wantfd > STDERR_FILENO
+ && (errno == ENFILE || errno == EMFILE)) {
+ (void) (*fp->_close)(fp->_cookie);
+ isopen = 0;
+ wantfd = -1;
+ f = _open(file, oflags, DEFFILEMODE);
+ }
sverrno = errno;
finish:

File Metadata

Mime Type
text/plain
Expires
Sat, Oct 11, 4:37 PM (15 h, 5 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
23584442
Default Alt Text
D442.id839.diff (2 KB)

Event Timeline