* misc/bits/syslog.h: New file.
authorUlrich Drepper <drepper@redhat.com>
Sat, 30 Jul 2005 06:00:43 +0000 (06:00 +0000)
committerUlrich Drepper <drepper@redhat.com>
Sat, 30 Jul 2005 06:00:43 +0000 (06:00 +0000)
* misc/sys/syslog.h: Include <bits/syslog.h> for fortification.
* misc/Makefile (headers): Add bits/syslog.h.
* include/sys/syslog.h: Add __vsyslog_chk prototype and hidden_proto.
* sysdeps/generic/syslog.c: Change vsyslog function to __vsyslog_chk.
Call __vfprintf_chk if necessary.  Make vsyslog a wrapper.  Add
__syslog_chk.
* misc/Versions: Export __syslog_chk and __vsyslog_chk.

* nis/nis_xdr.c: Help gcc to avoid generating unnecessary wrapper
functions.

ChangeLog
include/sys/syslog.h
misc/Makefile
misc/Versions
misc/sys/syslog.h
sysdeps/generic/syslog.c

index bb7f22d..41efaf6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,10 +1,22 @@
+2005-07-29  Ulrich Drepper  <drepper@redhat.com>
+
+       * misc/bits/syslog.h: New file.
+       * misc/sys/syslog.h: Include <bits/syslog.h> for fortification.
+       * misc/Makefile (headers): Add bits/syslog.h.
+       * include/sys/syslog.h: Add __vsyslog_chk prototype and hidden_proto.
+       * sysdeps/generic/syslog.c: Change vsyslog function to __vsyslog_chk.
+       Call __vfprintf_chk if necessary.  Make vsyslog a wrapper.  Add
+       __syslog_chk.
+       * misc/Versions: Export __syslog_chk and __vsyslog_chk.
+
 2005-07-28  Thomas Schwinge  <schwinge@nic-nac-project.de>
 
        * misc/error.c [_LIBC]: Include <stdbool.h> and <stdint.h>.
 
 2005-07-28  Ulrich Drepper  <drepper@redhat.com>
 
-       * nis/nis_xdr.c: Help gcc to generate unnecessary wrapper functions.
+       * nis/nis_xdr.c: Help gcc to avoid generating unnecessary wrapper
+       functions.
 
 2005-07-28  Jakub Jelinek  <jakub@redhat.com>
 
index e018225..8b0d59d 100644 (file)
@@ -2,3 +2,8 @@
 
 libc_hidden_proto (syslog)
 libc_hidden_proto (vsyslog)
+
+extern void __vsyslog_chk (int __pri, int __flag, __const char *__fmt,
+                          __gnuc_va_list __ap)
+     __attribute__ ((__format__ (__printf__, 3, 0)));
+libc_hidden_proto (__vsyslog_chk)
index cd5b64e..7c0b648 100644 (file)
@@ -29,7 +29,7 @@ headers       := sys/uio.h bits/uio.h sys/ioctl.h bits/ioctls.h bits/ioctl-types.h \
           sys/mman.h sys/param.h fstab.h mntent.h search.h err.h error.h \
           sys/queue.h sysexits.h syscall.h sys/syscall.h sys/swap.h \
           sys/select.h ustat.h sys/ustat.h bits/ustat.h sys/sysinfo.h \
-          regexp.h bits/select.h bits/mman.h sys/xattr.h
+          regexp.h bits/select.h bits/mman.h sys/xattr.h bits/syslog.h
 
 routines := brk sbrk sstk ioctl \
            readv writev \
index 13b38ee..4c3aafa 100644 (file)
@@ -130,4 +130,7 @@ libc {
   GLIBC_2.3.3 {
     remap_file_pages;
   }
+  GLIBC_2.4 {
+    __syslog_chk; __vsyslog_chk;
+  }
 }
index 5007525..9de7570 100644 (file)
@@ -188,7 +188,7 @@ extern int setlogmask (int __mask) __THROW;
    This function is a possible cancellation point and therefore not
    marked with __THROW.  */
 extern void syslog (int __pri, __const char *__fmt, ...)
-     __attribute__ ((__format__(__printf__, 2, 3)));
+     __attribute__ ((__format__ (__printf__, 2, 3)));
 
 #ifdef __USE_BSD
 /* Generate a log message using FMT and using arguments pointed to by AP.
@@ -198,7 +198,13 @@ extern void syslog (int __pri, __const char *__fmt, ...)
    or due to the implementation it is a cancellation point and
    therefore not marked with __THROW.  */
 extern void vsyslog (int __pri, __const char *__fmt, __gnuc_va_list __ap)
-     __attribute__ ((__format__(__printf__, 2, 0)));
+     __attribute__ ((__format__ (__printf__, 2, 0)));
+#endif
+
+
+/* Define some macros helping to catch buffer overflows.  */
+#if __USE_FORTIFY_LEVEL > 0 && !defined __cplusplus
+# include <bits/syslog.h>
 #endif
 
 __END_DECLS
index 9c8f422..9c5597f 100644 (file)
@@ -108,32 +108,28 @@ cancel_handler (void *ptr)
  *     print message on log file; output is intended for syslogd(8).
  */
 void
-#if __STDC__
 syslog(int pri, const char *fmt, ...)
-#else
-syslog(pri, fmt, va_alist)
-       int pri;
-       char *fmt;
-       va_dcl
-#endif
 {
        va_list ap;
 
-#if __STDC__
        va_start(ap, fmt);
-#else
-       va_start(ap);
-#endif
-       vsyslog(pri, fmt, ap);
+       __vsyslog_chk(pri, -1, fmt, ap);
        va_end(ap);
 }
 libc_hidden_def (syslog)
 
 void
-vsyslog(pri, fmt, ap)
-       int pri;
-       register const char *fmt;
+__syslog_chk(int pri, int flag, const char *fmt, ...)
+{
        va_list ap;
+
+       va_start(ap, fmt);
+       __vsyslog_chk(pri, flag, fmt, ap);
+       va_end(ap);
+}
+
+void
+__vsyslog_chk(int pri, int flag, const char *fmt, va_list ap)
 {
        struct tm now_tm;
        time_t now;
@@ -218,7 +214,10 @@ vsyslog(pri, fmt, ap)
 
            /* We have the header.  Print the user's format into the
                buffer.  */
-           vfprintf (f, fmt, ap);
+           if (flag == -1)
+             vfprintf (f, fmt, ap);
+           else
+             __vfprintf_chk (f, flag, fmt, ap);
 
            /* Close the memory stream; this will finalize the data
               into a malloc'd buffer in BUF.  */
@@ -315,6 +314,16 @@ vsyslog(pri, fmt, ap)
        if (buf != failbuf)
                free (buf);
 }
+libc_hidden_def (__vsyslog_chk)
+
+void
+vsyslog(pri, fmt, ap)
+       int pri;
+       register const char *fmt;
+       va_list ap;
+{
+  __vsyslog_chk (pri, -1, fmt, ap);
+}
 libc_hidden_def (vsyslog)
 
 static struct sockaddr SyslogAddr;     /* AF_UNIX address of local logger */