tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[PATCH 6/6] fdopen() opens successfully more descriptiors than STREAM_MAX



fdopen() should return EMFILE if amount of file descriptors exceeds STREAM_MAX
or FOPEN_MAX limit.
---
 include/stdio.h         |    2 +-
 lib/libc/stdio/fdopen.c |    5 ++++-
 sys/sys/sysctl.h        |    2 +-
 3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/include/stdio.h b/include/stdio.h
index 05ba32b..a8a15a9 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -179,7 +179,7 @@ __END_DECLS
  * stdio can provide without attempting to allocate further resources
  * (which could fail).  Do not use this for anything.
  */
-                               /* must be == _POSIX_STREAM_MAX <limits.h> */
+/*#define      STREAM_MAX      8*/     /* must be == _POSIX_STREAM_MAX 
<limits.h> */
 #define        FOPEN_MAX       20      /* must be <= OPEN_MAX 
<sys/syslimits.h> */
 #define        FILENAME_MAX    1024    /* must be <= PATH_MAX 
<sys/syslimits.h> */
 
diff --git a/lib/libc/stdio/fdopen.c b/lib/libc/stdio/fdopen.c
index e2f7a03..e8b3400 100644
--- a/lib/libc/stdio/fdopen.c
+++ b/lib/libc/stdio/fdopen.c
@@ -74,8 +74,11 @@ fdopen(fd, mode)
         * USHRT_MAX, then the fd will get sign-extended into an
         * invalid file descriptor.  Handle this case by failing the
         * open. (We treat the short as unsigned, and special-case -1).
+        *
+        * In other side we can't exceed the whether FOPEN_MAX or STREAM_MAX
+        * limits as SUSv3 requires. For both we're using FOPEN_MAX here.
         */
-       if (fd >= USHRT_MAX) {
+       if ((fd >= FOPEN_MAX) || (fd >= USHRT_MAX)) {
                errno = EMFILE;
                return NULL;
        }
diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h
index 8cc2cdc..3375fbe 100644
--- a/sys/sys/sysctl.h
+++ b/sys/sys/sysctl.h
@@ -851,7 +851,7 @@ struct kinfo_file {
 #define        USER_POSIX2_LOCALEDEF   16      /* int: POSIX2_LOCALEDEF */
 #define        USER_POSIX2_SW_DEV      17      /* int: POSIX2_SW_DEV */
 #define        USER_POSIX2_UPE         18      /* int: POSIX2_UPE */
-#define        USER_STREAM_MAX         19      /* int: POSIX2_STREAM_MAX */
+#define        USER_STREAM_MAX         19      /* int: _POSIX_STREAM_MAX */
 #define        USER_TZNAME_MAX         20      /* int: _POSIX_TZNAME_MAX */
 #define        USER_ATEXIT_MAX         21      /* int: {ATEXIT_MAX} */
 #define        USER_MAXID              22      /* number of valid user ids */
-- 
1.5.2.5



Home | Main Index | Thread Index | Old Index