]> git.ipfire.org Git - thirdparty/dhcp.git/commitdiff
[#15,!10] Addressed review comments
authorThomas Markwalder <tmark@isc.org>
Tue, 11 Jun 2019 17:38:59 +0000 (13:38 -0400)
committerThomas Markwalder <tmark@isc.org>
Wed, 12 Jun 2019 13:57:33 +0000 (09:57 -0400)
common/discover.c
    discover_interfaces() - replaced strncpy with memcpy

common/parse.c
    parse_warn() - added final message buffer rather than reuse mbuf,
    pass size into do_percentm call

includes/dhcpd.h
    struct interface_info  - restored size of name

includes/omapip/omapip_p.*
    do_percentm() - added output buffer size parameter

omapip/errwarn.c
    pass size of output buffer into calls to do_percentm

common/discover.c
common/parse.c
includes/dhcpd.h
includes/omapip/omapip_p.h
omapip/errwarn.c

index 6ef8852941320e610c44b31f6651f14e11c923af..226dbc4a73af495b0213ee6c4cbf2ef50b64a293 100644 (file)
@@ -643,7 +643,9 @@ discover_interfaces(int state) {
                                log_fatal("Error allocating interface %s: %s",
                                          info.name, isc_result_totext(status));
                        }
-                       strncpy(tmp->name, info.name, sizeof(tmp->name) - 1);
+
+                       memcpy(tmp->name, info.name, sizeof(tmp->name));
+
                        interface_snorf(tmp, ir);
                        interface_dereference(&tmp, MDL);
                        tmp = interfaces; /* XXX */
index 35b0b8de838f5506b9a11588669c18043922ca75..c0fa4050997b23caaab5c0b5f07ccb2bce4609da 100644 (file)
@@ -5566,19 +5566,25 @@ int parse_warn (struct parse *cfile, const char *fmt, ...)
 {
        va_list list;
        char lexbuf [256];
-       char mbuf [1024];
+       char mbuf [1024];  /* errorwarn.c CVT_BUF_MAX + 1 */
        char fbuf [2048];
+       char final[4096];
        unsigned i, lix;
-       
-       do_percentm (mbuf, fmt);
+
+       /* Replace %m in fmt with errno error text */
+       do_percentm (mbuf, sizeof(mbuf), fmt);
+
        /* %Audit% This is log output. %2004.06.17,Safe%
         * If we truncate we hope the user can get a hint from the log.
         */
+
+       /* Prepend the file and line number */
        snprintf (fbuf, sizeof fbuf, "%s line %d: %s",
                  cfile -> tlname, cfile -> lexline, mbuf);
-       
+
+       /* Now add the var args to the format for the final log message. */
        va_start (list, fmt);
-       vsnprintf (mbuf, sizeof mbuf, fbuf, list);
+       vsnprintf (final, sizeof final, fbuf, list);
        va_end (list);
 
        lix = 0;
@@ -5594,14 +5600,14 @@ int parse_warn (struct parse *cfile, const char *fmt, ...)
        lexbuf [lix] = 0;
 
 #ifndef DEBUG
-       syslog (LOG_ERR, "%s", mbuf);
+       syslog (LOG_ERR, "%s", final);
        syslog (LOG_ERR, "%s", cfile -> token_line);
        if (cfile -> lexchar < 81)
                syslog (LOG_ERR, "%s^", lexbuf);
 #endif
 
        if (log_perror) {
-               IGNORE_RET (write (STDERR_FILENO, mbuf, strlen (mbuf)));
+               IGNORE_RET (write (STDERR_FILENO, final, strlen (final)));
                IGNORE_RET (write (STDERR_FILENO, "\n", 1));
                IGNORE_RET (write (STDERR_FILENO, cfile -> token_line,
                                   strlen (cfile -> token_line)));
index 0ce3d00cfd9523df6f8dcd98854f011d86f4c45d..d4c81fc160b44c9542ea8c602ad5e290c5f0a428 100644 (file)
@@ -1392,7 +1392,8 @@ struct interface_info {
                                           interface (if any). */
        unsigned remote_id_len;         /* Length of Remote ID. */
 
-       char name [IFNAMSIZ+1];         /* Its name... */
+       char name [IFNAMSIZ];           /* Its name... */
+
        int index;                      /* Its if_nametoindex(). */
        int rfdesc;                     /* Its read file descriptor. */
        int wfdesc;                     /* Its write file descriptor, if
index 7fe1eba54988c2d6df4e19fe950885e48162b3b7..c92f942000f1ffd86cbae7d793ac999ad6f8abbb 100644 (file)
@@ -288,7 +288,8 @@ int log_info (const char *, ...)
        __attribute__((__format__(__printf__,1,2)));
 int log_debug (const char *, ...)
        __attribute__((__format__(__printf__,1,2)));
-void do_percentm (char *obuf, const char *ibuf);
+
+void do_percentm (char *obuf, size_t obufsize, const char *ibuf);
 
 isc_result_t uerr2isc (int);
 isc_result_t ns_rcode_to_isc (int);
index e30f8a0d1c75c5781e12a6cf38a54ec1031ce395..62e0d5ee12b6b5043dc9147b7b481999fcadfaa1 100644 (file)
@@ -54,7 +54,7 @@ void log_fatal (const char * fmt, ... )
 {
   va_list list;
 
-  do_percentm (fbuf, fmt);
+  do_percentm (fbuf, sizeof(fbuf), fmt);
 
   /* %Audit% This is log output. %2004.06.17,Safe%
    * If we truncate we hope the user can get a hint from the log.
@@ -93,7 +93,7 @@ int log_error (const char * fmt, ...)
 {
   va_list list;
 
-  do_percentm (fbuf, fmt);
+  do_percentm (fbuf, sizeof(fbuf), fmt);
 
   /* %Audit% This is log output. %2004.06.17,Safe%
    * If we truncate we hope the user can get a hint from the log.
@@ -120,7 +120,7 @@ int log_info (const char *fmt, ...)
 {
   va_list list;
 
-  do_percentm (fbuf, fmt);
+  do_percentm (fbuf, sizeof(fbuf), fmt);
 
   /* %Audit% This is log output. %2004.06.17,Safe%
    * If we truncate we hope the user can get a hint from the log.
@@ -147,7 +147,7 @@ int log_debug (const char *fmt, ...)
 {
   va_list list;
 
-  do_percentm (fbuf, fmt);
+  do_percentm (fbuf, sizeof(fbuf), fmt);
 
   /* %Audit% This is log output. %2004.06.17,Safe%
    * If we truncate we hope the user can get a hint from the log.
@@ -170,8 +170,9 @@ int log_debug (const char *fmt, ...)
 
 /* Find %m in the input string and substitute an error message string. */
 
-void do_percentm (obuf, ibuf)
+void do_percentm (obuf, obufsize, ibuf)
      char *obuf;
+     size_t obufsize;
      const char *ibuf;
 {
        const char *s = ibuf;
@@ -191,13 +192,13 @@ void do_percentm (obuf, ibuf)
                                if (!m)
                                        m = "<unknown error>";
                                len += strlen (m);
-                               if (len > CVT_BUF_MAX)
+                               if (len > obufsize - 1)
                                        goto out;
                                strcpy (p - 1, m);
                                p += strlen (p);
                                ++s;
                        } else {
-                               if (++len > CVT_BUF_MAX)
+                               if (++len > obufsize - 1)
                                        goto out;
                                *p++ = *s++;
                        }
@@ -205,7 +206,7 @@ void do_percentm (obuf, ibuf)
                } else {
                        if (*s == '%')
                                infmt = 1;
-                       if (++len > CVT_BUF_MAX)
+                       if (++len > obufsize - 1)
                                goto out;
                        *p++ = *s++;
                }