This is the mail archive of the cygwin-developers@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

fopen looking past end of mode string



When fopen is checking its mode flags, it can look past
the end of the string.  This patch checks that mode[1] is
not a terminator before looking ahead to mode[2].

Eric Fifer

--- newlib/libc/stdio/flags.c-  Thu Oct 14 18:37:59 1999
+++ newlib/libc/stdio/flags.c   Mon Jan 31 14:33:53 2000
@@ -61,19 +61,19 @@
       ptr->_errno = EINVAL;
       return (0);
     }
-  if (mode[1] == '+' || mode[2] == '+')
+  if (mode[1] && (mode[1] == '+' || mode[2] == '+'))
     {
       ret = __SRW;
       m = O_RDWR;
     }
-  if (mode[1] == 'b' || mode[2] == 'b')
+  if (mode[1] && (mode[1] == 'b' || mode[2] == 'b'))
     {
 #ifdef O_BINARY
       m |= O_BINARY;
 #endif
     }
 #ifdef __CYGWIN__
-  else if (mode[1] == 't' || mode[2] == 't')
+  else if (mode[1] && (mode[1] == 't' || mode[2] == 't'))
 #else
   else
 #endif

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]