]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Update.
authorUlrich Drepper <drepper@redhat.com>
Thu, 18 Nov 2004 23:25:46 +0000 (23:25 +0000)
committerUlrich Drepper <drepper@redhat.com>
Thu, 18 Nov 2004 23:25:46 +0000 (23:25 +0000)
2004-11-18  Ulrich Drepper  <drepper@redhat.com>
* libio/libio.h (_IO_FLAGS2_FORTIFY): Renamed from
_IO_FLAGS2_CHECK_PERCENT_N.
* debug/fprintff_chk.c: Adjust all users.
* debug/printf_chk.c: Likewise.
* debug/vfprintf_chk.c: Likewise.
* debug/vprintf_chk.c: Likewise.
* debug/vsnprintf_chk.c: Likewise.
* debug/vsprintf_chk.c: Likewise.
* stdio-common/vfprintf.c: Likewise.  Detect missing %N$ formats.
* debug/tst-chk1.c: Test detection of missing %N$ formats.

ChangeLog
debug/fprintf_chk.c
debug/printf_chk.c
debug/tst-chk1.c
debug/vfprintf_chk.c
debug/vprintf_chk.c
debug/vsnprintf_chk.c
debug/vsprintf_chk.c
stdio-common/vfprintf.c

index 2b5b698794ed2c64b609b2e8f7b17ef3b1db5b0d..d973d887077666709c7cfa49bcc847981ce548f5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,15 @@
-2004-11-17  Alfred M. Szmidt  <ams@gnu.org>
+2004-11-18  Ulrich Drepper  <drepper@redhat.com>
 
-       * sysdeps/posix/libc_fatal.c: Include <sys/uio.h>.
+       * libio/libio.h (_IO_FLAGS2_FORTIFY): Renamed from
+       _IO_FLAGS2_CHECK_PERCENT_N.
+       * debug/fprintff_chk.c: Adjust all users.
+       * debug/printf_chk.c: Likewise.
+       * debug/vfprintf_chk.c: Likewise.
+       * debug/vprintf_chk.c: Likewise.
+       * debug/vsnprintf_chk.c: Likewise.
+       * debug/vsprintf_chk.c: Likewise.
+       * stdio-common/vfprintf.c: Likewise.  Detect missing %N$ formats.
+       * debug/tst-chk1.c: Test detection of missing %N$ formats.
 
 2004-11-15  Jakub Jelinek  <jakub@redhat.com>
 
index 77508b902e06ce05224187843325f6850be492b1..2b7d22b6a6eb3fbe136d0e75fbb08774753128ca 100644 (file)
@@ -31,14 +31,14 @@ __fprintf_chk (FILE *fp, int flag, const char *format, ...)
 
   _IO_acquire_lock (fp);
   if (flag > 0)
-    fp->_flags2 |= _IO_FLAGS2_CHECK_PERCENT_N;
+    fp->_flags2 |= _IO_FLAGS2_FORTIFY;
 
   va_start (ap, format);
   done = vfprintf (fp, format, ap);
   va_end (ap);
 
   if (flag > 0)
-    fp->_flags2 &= ~_IO_FLAGS2_CHECK_PERCENT_N;
+    fp->_flags2 &= ~_IO_FLAGS2_FORTIFY;
   _IO_release_lock (fp);
 
   return done;
index d2b387323d7f94439af54193d1240c2884868319..86096b45c0f6e05a5283849ba42e45a5ce5bf397 100644 (file)
@@ -31,14 +31,14 @@ __printf_chk (int flag, const char *format, ...)
 
   _IO_acquire_lock (stdout);
   if (flag > 0)
-    stdout->_flags2 |= _IO_FLAGS2_CHECK_PERCENT_N;
+    stdout->_flags2 |= _IO_FLAGS2_FORTIFY;
 
   va_start (ap, format);
   done = vfprintf (stdout, format, ap);
   va_end (ap);
 
   if (flag > 0)
-    stdout->_flags2 &= ~_IO_FLAGS2_CHECK_PERCENT_N;
+    stdout->_flags2 &= ~_IO_FLAGS2_FORTIFY;
   _IO_release_lock (stdout);
 
   return done;
index 37320c3514f458eca08a554e1e88057a39869ca2..0df660d57f12681d4663ec1ad3db16a1240c0ad5 100644 (file)
@@ -474,5 +474,22 @@ do_test (void)
   CHK_FAIL_END
 #endif
 
+  /* Check whether missing N$ formats are detected.  */
+  CHK_FAIL2_START
+  printf ("%3$d\n", 1, 2, 3, 4);
+  CHK_FAIL2_END
+
+  CHK_FAIL2_START
+  fprintf (stdout, "%3$d\n", 1, 2, 3, 4);
+  CHK_FAIL2_END
+
+  CHK_FAIL2_START
+  sprintf (buf, "%3$d\n", 1, 2, 3, 4);
+  CHK_FAIL2_END
+
+  CHK_FAIL2_START
+  snprintf (buf, sizeof (buf), "%3$d\n", 1, 2, 3, 4);
+  CHK_FAIL2_END
+
   return ret;
 }
index a9e107d8e5c03df358fbafbe8ea355c8531b6735..c8e7c3bf3fc3538679f0ea8a9bca7e1798b03261 100644 (file)
@@ -30,12 +30,12 @@ __vfprintf_chk (FILE *fp, int flag, const char *format, va_list ap)
 
   _IO_acquire_lock (fp);
   if (flag > 0)
-    fp->_flags2 |= _IO_FLAGS2_CHECK_PERCENT_N;
+    fp->_flags2 |= _IO_FLAGS2_FORTIFY;
 
   done = vfprintf (fp, format, ap);
 
   if (flag > 0)
-    fp->_flags2 &= ~_IO_FLAGS2_CHECK_PERCENT_N;
+    fp->_flags2 &= ~_IO_FLAGS2_FORTIFY;
   _IO_release_lock (fp);
 
   return done;
index f477f1541191ec195b1822fc5085c8017de9a1b6..1fd5bcd849627d0061fe3f42caf0712b98193fff 100644 (file)
@@ -30,12 +30,12 @@ __vprintf_chk (int flag, const char *format, va_list ap)
 
   _IO_acquire_lock (stdout);
   if (flag > 0)
-    stdout->_flags2 |= _IO_FLAGS2_CHECK_PERCENT_N;
+    stdout->_flags2 |= _IO_FLAGS2_FORTIFY;
 
   done = vfprintf (stdout, format, ap);
 
   if (flag > 0)
-    stdout->_flags2 &= ~_IO_FLAGS2_CHECK_PERCENT_N;
+    stdout->_flags2 &= ~_IO_FLAGS2_FORTIFY;
   _IO_release_lock (stdout);
 
   return done;
index 850cd5af5a936b834eddea32e6b70ff41b50e255..a0fd4ebfdc6f04fd03bf57180331fe60da980636 100644 (file)
@@ -58,7 +58,7 @@ __vsnprintf_chk (char *s, size_t maxlen, int flags, size_t slen,
   /* For flags > 0 (i.e. __USE_FORTIFY_LEVEL > 1) request that %n
      can only come from read-only format strings.  */
   if (flags > 0)
-    sf.f._sbf._f._flags2 |= _IO_FLAGS2_CHECK_PERCENT_N;
+    sf.f._sbf._f._flags2 |= _IO_FLAGS2_FORTIFY;
 
   _IO_str_init_static_internal (&sf.f, s, maxlen - 1, s);
   ret = INTUSE(_IO_vfprintf) ((_IO_FILE *) &sf.f._sbf, format, args);
index 83383286da18f60982c8bef5c09fded9ebb2e359..f41c5fc64bd0e1c3dd9f5a4911ac43fd38b0947d 100644 (file)
@@ -81,7 +81,7 @@ __vsprintf_chk (char *s, int flags, size_t slen, const char *format,
   /* For flags > 0 (i.e. __USE_FORTIFY_LEVEL > 1) request that %n
      can only come from read-only format strings.  */
   if (flags > 0)
-    f._sbf._f._flags2 |= _IO_FLAGS2_CHECK_PERCENT_N;
+    f._sbf._f._flags2 |= _IO_FLAGS2_FORTIFY;
 
   ret = INTUSE(_IO_vfprintf) ((_IO_FILE *) &f._sbf, format, args);
 
index 5e480ad52b78a9dccecdd8ca393fd181d66ae3db..3f0e1dee5e1708f53cbb4cfa331c26eadc5556dc 100644 (file)
@@ -882,18 +882,18 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
       /* NOTREACHED */                                                       \
                                                                              \
     LABEL (form_number):                                                     \
-      if (s->_flags2 & _IO_FLAGS2_CHECK_PERCENT_N)                           \
+      if (s->_flags2 & _IO_FLAGS2_FORTIFY)                                   \
        {                                                                     \
          if (! readonly_format)                                              \
            {                                                                 \
              extern int __readonly_area (const void *, size_t)               \
                attribute_hidden;                                             \
              readonly_format                                                 \
-               = __readonly_area (format, (STR_LEN (format) + 1)             \
-                                          * sizeof (CHAR_T));                \
+               = __readonly_area (format, ((STR_LEN (format) + 1)            \
+                                           * sizeof (CHAR_T)));              \
            }                                                                 \
          if (readonly_format < 0)                                            \
-           __chk_fail ();                                                    \
+           __libc_fatal ("*** %n is writable segment detected ***\n");       \
        }                                                                     \
       /* Answer the count of characters written.  */                         \
       if (fspec == NULL)                                                     \
@@ -1649,7 +1649,8 @@ do_positional:
 
     /* Allocate memory for the argument descriptions.  */
     args_type = alloca (nargs * sizeof (int));
-    memset (args_type, 0, nargs * sizeof (int));
+    memset (args_type, s->_flags2 & _IO_FLAGS2_FORTIFY ? '\xff' : '\0',
+           nargs * sizeof (int));
     args_value = alloca (nargs * sizeof (union printf_arg));
 
     /* XXX Could do sanity check here: If any element in ARGS_TYPE is
@@ -1714,6 +1715,11 @@ do_positional:
          else
            args_value[cnt].pa_long_double = 0.0;
          break;
+       case -1:
+         /* Error case.  Not all parameters appear in N$ format
+            strings.  We have no way to determine their type.  */
+         assert (s->_flags2 & _IO_FLAGS2_FORTIFY);
+         __libc_fatal ("*** invalid %N$ use detected ***\n");
        }
 
     /* Now walk through all format specifiers and process them.  */