Source-Changes-HG archive

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

[src/trunk]: src/external/bsd/ntp - document non-literal strings



details:   https://anonhg.NetBSD.org/src/rev/3a9be96a5f23
branches:  trunk
changeset: 768386:3a9be96a5f23
user:      christos <christos%NetBSD.org@localhost>
date:      Tue Aug 16 05:15:20 2011 +0000

description:
- document non-literal strings
- fix bad security practices: {msyslog,syslog,printf}(buffer) ->
    {msyslog,syslog,printf}("%s", buffer)
- use an anonymous union to avoid type punning casts
- re-order expression to avoid integer overflow

diffstat:

 external/bsd/ntp/bin/ntpd/Makefile            |   7 +-
 external/bsd/ntp/dist/include/ntp_request.h   |  90 ++++++++++++++------------
 external/bsd/ntp/dist/ntpd/ntp_config.c       |   4 +-
 external/bsd/ntp/dist/ntpd/ntp_control.c      |   7 +-
 external/bsd/ntp/dist/ntpd/ntp_request.c      |  12 +-
 external/bsd/ntp/dist/ntpd/ntpd.c             |   6 +-
 external/bsd/ntp/dist/ntpd/refclock_jupiter.c |   4 +-
 external/bsd/ntp/dist/ntpd/refclock_oncore.c  |   4 +-
 8 files changed, 68 insertions(+), 66 deletions(-)

diffs (truncated from 326 to 300 lines):

diff -r d0118c7552a8 -r 3a9be96a5f23 external/bsd/ntp/bin/ntpd/Makefile
--- a/external/bsd/ntp/bin/ntpd/Makefile        Tue Aug 16 04:45:17 2011 +0000
+++ b/external/bsd/ntp/bin/ntpd/Makefile        Tue Aug 16 05:15:20 2011 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.9 2011/06/22 02:49:42 mrg Exp $
+#      $NetBSD: Makefile,v 1.10 2011/08/16 05:15:20 christos Exp $
 
 #NOGCCERROR=yes
 
@@ -90,13 +90,10 @@
        ${TOOL_SED} -e "s,NTPD 1,NTPD 8," $? > $@
 
 CLEANFILES+=ntpd.8
+COPTS.ntp_control.c+= -Wno-format-nonliteral
 
 .include <bsd.prog.mk>
 
 # kill default .y.c rule - to rebuild ntp_parser.c we need bison which is not part of the toolchain
 .y.c:
 
-# XXX
-.if ${HAVE_GCC} == 45
-COPTS.ntp_request.c+= -Wno-error -fno-strict-aliasing
-.endif
diff -r d0118c7552a8 -r 3a9be96a5f23 external/bsd/ntp/dist/include/ntp_request.h
--- a/external/bsd/ntp/dist/include/ntp_request.h       Tue Aug 16 04:45:17 2011 +0000
+++ b/external/bsd/ntp/dist/include/ntp_request.h       Tue Aug 16 05:15:20 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ntp_request.h,v 1.1.1.1 2009/12/13 16:54:53 kardel Exp $       */
+/*     $NetBSD: ntp_request.h,v 1.2 2011/08/16 05:15:20 christos Exp $ */
 
 /*
  * ntp_request.h - definitions for the ntpd remote query facility
@@ -125,6 +125,44 @@
 };
 
 /*
+ * Structure for carrying system flags.
+ */
+struct conf_sys_flags {
+       u_int32 flags;
+};
+
+/*
+ * System flags we can set/clear
+ */
+#define        SYS_FLAG_BCLIENT        0x01
+#define        SYS_FLAG_PPS            0x02
+#define SYS_FLAG_NTP           0x04
+#define SYS_FLAG_KERNEL                0x08
+#define SYS_FLAG_MONITOR       0x10
+#define SYS_FLAG_FILEGEN       0x20
+#define SYS_FLAG_AUTH          0x40
+#define SYS_FLAG_CAL           0x80
+
+/*
+ * Structure used for passing indication of flags to clear
+ */
+struct reset_flags {
+       u_int32 flags;
+};
+
+#define        RESET_FLAG_ALLPEERS     0x01
+#define        RESET_FLAG_IO           0x02
+#define        RESET_FLAG_SYS          0x04
+#define        RESET_FLAG_MEM          0x08
+#define        RESET_FLAG_TIMER        0x10
+#define        RESET_FLAG_AUTH         0x20
+#define        RESET_FLAG_CTL          0x40
+
+#define        RESET_ALLFLAGS \
+       (RESET_FLAG_ALLPEERS|RESET_FLAG_IO|RESET_FLAG_SYS \
+       |RESET_FLAG_MEM|RESET_FLAG_TIMER|RESET_FLAG_AUTH|RESET_FLAG_CTL)
+
+/*
  * A request packet.  These are almost a fixed length.
  */
 struct req_pkt {
@@ -134,8 +172,12 @@
        u_char request;                 /* request number */
        u_short err_nitems;             /* error code/number of data items */
        u_short mbz_itemsize;           /* item size */
-       char data[MAXFILENAME + 48];    /* data area [32 prev](176 byte max) */
-                                       /* struct conf_peer must fit */
+       union {
+           char data[MAXFILENAME + 48];/* data area [32 prev](176 byte max) */
+           struct conf_sys_flags c_s_flags;
+           struct reset_flags r_flags;
+           u_int32_t ui;
+       };
        l_fp tstamp;                    /* time stamp, for authentication */
        keyid_t keyid;                  /* (optional) encryption key */
        char mac[MAX_MAC_LEN-sizeof(keyid_t)]; /* (optional) auth code */
@@ -217,8 +259,8 @@
 
 #define        INFO_ERR(err_nitems)    ((u_short)((ntohs(err_nitems)>>12)&0xf))
 #define        INFO_NITEMS(err_nitems) ((u_short)(ntohs(err_nitems)&0xfff))
-#define        ERR_NITEMS(err, nitems) (htons((u_short)((((u_short)(err)<<12)&0xf000)\
-                               |((u_short)(nitems)&0xfff))))
+#define _ERR_EN(err)           ((u_short)(((err)&0xf)<<12))
+#define        ERR_NITEMS(err, nitems) ((u_short)htons(_ERR_EN(err)|(nitems&0xfff)))
 
 #define        INFO_MBZ(mbz_itemsize)  ((ntohs(mbz_itemsize)>>12)&0xf)
 #define        INFO_ITEMSIZE(mbz_itemsize)     ((u_short)(ntohs(mbz_itemsize)&0xfff))
@@ -618,25 +660,6 @@
 };
 
 /*
- * Structure for carrying system flags.
- */
-struct conf_sys_flags {
-       u_int32 flags;
-};
-
-/*
- * System flags we can set/clear
- */
-#define        SYS_FLAG_BCLIENT        0x01
-#define        SYS_FLAG_PPS            0x02
-#define SYS_FLAG_NTP           0x04
-#define SYS_FLAG_KERNEL                0x08
-#define SYS_FLAG_MONITOR       0x10
-#define SYS_FLAG_FILEGEN       0x20
-#define SYS_FLAG_AUTH          0x40
-#define SYS_FLAG_CAL           0x80
-
-/*
  * Structure used for returning restrict entries
  */
 struct info_restrict {
@@ -720,25 +743,6 @@
 };
 
 /*
- * Structure used for passing indication of flags to clear
- */
-struct reset_flags {
-       u_int32 flags;
-};
-
-#define        RESET_FLAG_ALLPEERS     0x01
-#define        RESET_FLAG_IO           0x02
-#define        RESET_FLAG_SYS          0x04
-#define        RESET_FLAG_MEM          0x08
-#define        RESET_FLAG_TIMER        0x10
-#define        RESET_FLAG_AUTH         0x20
-#define        RESET_FLAG_CTL          0x40
-
-#define        RESET_ALLFLAGS \
-       (RESET_FLAG_ALLPEERS|RESET_FLAG_IO|RESET_FLAG_SYS \
-       |RESET_FLAG_MEM|RESET_FLAG_TIMER|RESET_FLAG_AUTH|RESET_FLAG_CTL)
-
-/*
  * Structure used to return information concerning the authentication
  * module.
  */
diff -r d0118c7552a8 -r 3a9be96a5f23 external/bsd/ntp/dist/ntpd/ntp_config.c
--- a/external/bsd/ntp/dist/ntpd/ntp_config.c   Tue Aug 16 04:45:17 2011 +0000
+++ b/external/bsd/ntp/dist/ntpd/ntp_config.c   Tue Aug 16 05:15:20 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ntp_config.c,v 1.3 2010/12/04 23:08:35 christos Exp $  */
+/*     $NetBSD: ntp_config.c,v 1.4 2011/08/16 05:15:21 christos Exp $  */
 
 /* ntp_config.c
  *
@@ -2299,7 +2299,7 @@
                if ((RES_MSSNTP & flags) && !warned_signd) {
                        warned_signd = 1;
                        fprintf(stderr, "%s\n", signd_warning);
-                       msyslog(LOG_WARNING, signd_warning);
+                       msyslog(LOG_WARNING, "%s", signd_warning);
                }
        }
 }
diff -r d0118c7552a8 -r 3a9be96a5f23 external/bsd/ntp/dist/ntpd/ntp_control.c
--- a/external/bsd/ntp/dist/ntpd/ntp_control.c  Tue Aug 16 04:45:17 2011 +0000
+++ b/external/bsd/ntp/dist/ntpd/ntp_control.c  Tue Aug 16 05:15:20 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ntp_control.c,v 1.3 2011/07/01 02:18:54 mrg Exp $      */
+/*     $NetBSD: ntp_control.c,v 1.4 2011/08/16 05:15:21 christos Exp $ */
 
 /*
  * ntp_control.c - respond to control messages and send async traps
@@ -607,6 +607,7 @@
         * allow timestamping of the saved config filename with
         * strftime() format such as:
         *   ntpq -c "saveconfig ntp-%Y%m%d-%H%M%S.conf"
+        * XXX: Nice feature, but not too safe.
         */
        if (0 == strftime(filename, sizeof(filename), filespec,
                               localtime(&now)))
@@ -2946,7 +2947,7 @@
                            " %s", str);
                }
                NLOG(NLOG_SYSEVENT)
-                   msyslog(LOG_INFO, statstr);
+                   msyslog(LOG_INFO, "%s", statstr);
        } else {
 
                /*
@@ -2978,7 +2979,7 @@
                            " %s", str);
                }
                NLOG(NLOG_PEEREVENT)
-                   msyslog(LOG_INFO, statstr);
+                   msyslog(LOG_INFO, "%s", statstr);
        }
        record_proto_stats(statstr);
 #if DEBUG
diff -r d0118c7552a8 -r 3a9be96a5f23 external/bsd/ntp/dist/ntpd/ntp_request.c
--- a/external/bsd/ntp/dist/ntpd/ntp_request.c  Tue Aug 16 04:45:17 2011 +0000
+++ b/external/bsd/ntp/dist/ntpd/ntp_request.c  Tue Aug 16 05:15:20 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ntp_request.c,v 1.4 2010/12/04 23:08:35 christos Exp $ */
+/*     $NetBSD: ntp_request.c,v 1.5 2011/08/16 05:15:21 christos Exp $ */
 
 /*
  * ntp_request.c - respond to information requests
@@ -261,7 +261,7 @@
        rpkt.auth_seq = AUTH_SEQ(0, 0);
        rpkt.implementation = inpkt->implementation;
        rpkt.request = inpkt->request;
-       rpkt.err_nitems = ERR_NITEMS(errcode, 0);
+       rpkt.err_nitems = ERR_NITEMS(errcode, 0); 
        rpkt.mbz_itemsize = MBZ_ITEMSIZE(0);
 
        /*
@@ -1693,7 +1693,7 @@
                return;
        }
 
-       flags = ((struct conf_sys_flags *)inpkt->data)->flags;
+       flags = inpkt->c_s_flags.flags;
        flags = ntohl(flags);
        
        if (flags & ~(SYS_FLAG_BCLIENT | SYS_FLAG_PPS |
@@ -2048,7 +2048,7 @@
                return;
        }
 
-       flags = ((struct reset_flags *)inpkt->data)->flags;
+       flags = inpkt->r_flags.flags;
        flags = ntohl(flags);
      
        if (flags & ~RESET_ALLFLAGS) {
@@ -2472,7 +2472,7 @@
                return;
        }
 
-       keyid = ntohl(*((u_int32 *)(inpkt->data)));
+       keyid = ntohl(inpkt->ui);
        info_auth_keyid = keyid;
        req_ack(srcadr, inter, inpkt, INFO_OKAY);
 }
@@ -2501,7 +2501,7 @@
                return;
        }
 
-       keyid = ntohl(*((u_int32 *)(inpkt->data)));
+       keyid = ntohl(inpkt->ui);
        ctl_auth_keyid = keyid;
        req_ack(srcadr, inter, inpkt, INFO_OKAY);
 }
diff -r d0118c7552a8 -r 3a9be96a5f23 external/bsd/ntp/dist/ntpd/ntpd.c
--- a/external/bsd/ntp/dist/ntpd/ntpd.c Tue Aug 16 04:45:17 2011 +0000
+++ b/external/bsd/ntp/dist/ntpd/ntpd.c Tue Aug 16 05:15:20 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ntpd.c,v 1.4 2010/11/29 00:39:41 christos Exp $        */
+/*     $NetBSD: ntpd.c,v 1.5 2011/08/16 05:15:21 christos Exp $        */
 
 /*
  * ntpd.c - main program for the fixed point NTP daemon
@@ -1266,7 +1266,7 @@
 
        msyslog(LOG_ERR, "%s:%d: fatal error:", file, line);
        vsnprintf(errbuf, sizeof(errbuf), format, args);
-       msyslog(LOG_ERR, errbuf);
+       msyslog(LOG_ERR, "%s", errbuf);
        msyslog(LOG_ERR, "exiting (due to fatal error in library)");
 
        abort();
@@ -1288,7 +1288,7 @@
 
        msyslog(LOG_ERR, "%s:%d: unexpected error:", file, line);
        vsnprintf(errbuf, sizeof(errbuf), format, args);
-       msyslog(LOG_ERR, errbuf);
+       msyslog(LOG_ERR, "%s", errbuf);
 
        if (++unexpected_error_cnt == MAX_UNEXPECTED_ERRORS)
        {
diff -r d0118c7552a8 -r 3a9be96a5f23 external/bsd/ntp/dist/ntpd/refclock_jupiter.c
--- a/external/bsd/ntp/dist/ntpd/refclock_jupiter.c     Tue Aug 16 04:45:17 2011 +0000
+++ b/external/bsd/ntp/dist/ntpd/refclock_jupiter.c     Tue Aug 16 05:15:20 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: refclock_jupiter.c,v 1.2 2010/12/04 23:08:35 christos Exp $    */
+/*     $NetBSD: refclock_jupiter.c,v 1.3 2011/08/16 05:15:21 christos Exp $    */
 
 /*
  * Copyright (c) 1997, 1998, 2003
@@ -904,7 +904,7 @@



Home | Main Index | Thread Index | Old Index