]> git.ipfire.org Git - thirdparty/dhcp.git/commitdiff
[#15] Changes to eliminate errors and warnings under GCC 9
authorThomas Markwalder <tmark@isc.org>
Fri, 8 Nov 2019 17:26:05 +0000 (12:26 -0500)
committerThomas Markwalder <tmark@isc.org>
Fri, 8 Nov 2019 17:26:05 +0000 (12:26 -0500)
    Merges changes for #15,!10 into v4_1_esv

RELNOTES
common/discover.c
common/parse.c
common/tests/option_unittest.c [new file with mode: 0644]
includes/dhcpd.h
includes/omapip/omapip_p.h
omapip/errwarn.c
relay/dhcrelay.c
server/confpars.c

index eba2bf6ae2ed6bb54833d06bde60ae9fd05cfb4f..7499c845bc0a5b73e6d10988368767fa36067613 100644 (file)
--- a/RELNOTES
+++ b/RELNOTES
@@ -72,6 +72,12 @@ We welcome comments from DHCP users, about this or anything else we do.
 Email Vicky Risk, Product Manager at vicky@isc.org or discuss on
 dhcp-users@lists.isc.org.
 
+                       Changes since 4.1-ESV-R15-P1
+
+- Made minor changes to eliminate warnings when compiled with GCC 9.
+  Thanks to Brett Neumeier for bringing the matter to our attention.
+  [Gitlab #15]
+
                        Changes since 4.1-ESV-R15
 
 - Corrected dhclient command line parsing for --dad-wait-time that causes
index 706a08c1f4bbfa6cc4d453edce4d08da8361be51..d6115b34c71d4a5a3b01e750a9b34f22e516cbe1 100644 (file)
@@ -629,7 +629,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 4b21c31069fbf642bffbd04282dd62ea6f00601b..ff31e28c7b62420637e50f7e70e014284ff9ac48 100644 (file)
@@ -3,7 +3,7 @@
    Common parser code for dhcpd and dhclient. */
 
 /*
- * Copyright (c) 2004-2017 by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (c) 2004-2019 by Internet Systems Consortium, Inc. ("ISC")
  * Copyright (c) 1995-2003 by Internet Software Consortium
  *
  * Permission to use, copy, modify, and distribute this software for any
@@ -5801,19 +5801,25 @@ int parse_warn (struct parse *cfile, const char *fmt, ...)
 {
        va_list list;
        char lexbuf [256];
-       char mbuf [1024];
-       char fbuf [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;
@@ -5829,14 +5835,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)));
diff --git a/common/tests/option_unittest.c b/common/tests/option_unittest.c
new file mode 100644 (file)
index 0000000..cd52cfb
--- /dev/null
@@ -0,0 +1,142 @@
+/*
+ * Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS.         IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <config.h>
+#include <atf-c.h>
+#include "dhcpd.h"
+
+ATF_TC(option_refcnt);
+
+ATF_TC_HEAD(option_refcnt, tc)
+{
+    atf_tc_set_md_var(tc, "descr",
+                     "Verify option reference count does not overflow.");
+}
+
+/* This test does a simple check to see if option reference count is
+ * decremented even an error path exiting parse_option_buffer()
+ */
+ATF_TC_BODY(option_refcnt, tc)
+{
+    struct option_state *options;
+    struct option *option;
+    unsigned code;
+    int refcnt;
+    unsigned char buffer[3] = { 15, 255, 0 };
+
+    initialize_common_option_spaces();
+
+    options = NULL;
+    if (!option_state_allocate(&options, MDL)) {
+       atf_tc_fail("can't allocate option state");
+    }
+
+    option = NULL;
+    code = 15; /* domain-name */
+    if (!option_code_hash_lookup(&option, dhcp_universe.code_hash,
+                                &code, 0, MDL)) {
+       atf_tc_fail("can't find option 15");
+    }
+    if (option == NULL) {
+       atf_tc_fail("option is NULL");
+    }
+    refcnt = option->refcnt;
+
+    buffer[0] = 15;
+    buffer[1] = 255; /* invalid */
+    buffer[2] = 0;
+
+    if (parse_option_buffer(options, buffer, 3, &dhcp_universe)) {
+       atf_tc_fail("parse_option_buffer is expected to fail");
+    }
+
+    if (refcnt != option->refcnt) {
+       atf_tc_fail("refcnt changed from %d to %d", refcnt, option->refcnt);
+    }
+}
+
+ATF_TC(pretty_print_option);
+
+ATF_TC_HEAD(pretty_print_option, tc)
+{
+    atf_tc_set_md_var(tc, "descr",
+                     "Verify pretty_print_option does not overrun its buffer.");
+}
+
+
+/*
+ * This test verifies that pretty_print_option() will not overrun its
+ * internal, static buffer when given large 'x/X' format options.
+ *
+ */
+ATF_TC_BODY(pretty_print_option, tc)
+{
+    struct option *option;
+    unsigned code;
+    unsigned char bad_data[32*1024];
+    unsigned char good_data[] = { 1,2,3,4,5,6 };
+    int emit_commas = 1;
+    int emit_quotes = 1;
+    const char *output_buf;
+
+    /* Initialize whole thing to non-printable chars */
+    memset(bad_data, 0x1f, sizeof(bad_data));
+
+    initialize_common_option_spaces();
+
+    /* We'll use dhcp_client_identitifer because it happens to be format X */
+    code = 61;
+    option = NULL;
+    if (!option_code_hash_lookup(&option, dhcp_universe.code_hash,
+                                &code, 0, MDL)) {
+           atf_tc_fail("can't find option %d", code);
+    }
+
+    if (option == NULL) {
+           atf_tc_fail("option is NULL");
+    }
+
+    /* First we will try a good value we know should fit. */
+    output_buf = pretty_print_option (option, good_data, sizeof(good_data),
+                                      emit_commas, emit_quotes);
+
+    /* Make sure we get what we expect */
+    if (!output_buf || strcmp(output_buf, "1:2:3:4:5:6")) {
+           atf_tc_fail("pretty_print_option did not return \"<error>\"");
+    }
+
+
+    /* Now we'll try a data value that's too large */
+    output_buf = pretty_print_option (option, bad_data, sizeof(bad_data),
+                                      emit_commas, emit_quotes);
+
+    /* Make sure we safely get an error */
+    if (!output_buf || strcmp(output_buf, "<error>")) {
+           atf_tc_fail("pretty_print_option did not return \"<error>\"");
+    }
+}
+
+
+/* This macro defines main() method that will call specified
+   test cases. tp and simple_test_case names can be whatever you want
+   as long as it is a valid variable identifier. */
+ATF_TP_ADD_TCS(tp)
+{
+    ATF_TP_ADD_TC(tp, option_refcnt);
+    ATF_TP_ADD_TC(tp, pretty_print_option);
+
+    return (atf_no_error());
+}
index d05dc7598d6a2fef69ccf21215531c5a96057ffc..6643dc4d7e03b0765f8cef27257a2e18c7847231 100644 (file)
@@ -3,7 +3,7 @@
    Definitions for dhcpd... */
 
 /*
- * Copyright (c) 2004-2017 by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (c) 2004-2019 by Internet Systems Consortium, Inc. ("ISC")
  * Copyright (c) 1996-2003 by Internet Software Consortium
  *
  * Permission to use, copy, modify, and distribute this software for any
@@ -1141,6 +1141,7 @@ struct interface_info {
        unsigned remote_id_len;         /* Length of Remote ID. */
 
        char name [IFNAMSIZ];           /* Its name... */
+
        int index;                      /* Its if_nametoindex(). */
        int rfdesc;                     /* Its read file descriptor. */
        int wfdesc;                     /* Its write file descriptor, if
index 8932f5df750f84ca03927afc07ae476a9aa9a469..4369410d72053c06bfbe7fa3449d56116b709c74 100644 (file)
@@ -281,7 +281,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 a6ed209f9e3d99caf54bae6e46538a9d37bcd9ef..42a3fad2a1b0e1a6bac442147f5ec6ef8257bd09 100644 (file)
@@ -55,7 +55,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.
@@ -104,7 +104,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.
@@ -131,7 +131,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.
@@ -158,7 +158,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.
@@ -181,8 +181,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;
@@ -202,13 +203,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++;
                        }
@@ -216,7 +217,7 @@ void do_percentm (obuf, ibuf)
                } else {
                        if (*s == '%')
                                infmt = 1;
-                       if (++len > CVT_BUF_MAX)
+                       if (++len > obufsize - 1)
                                goto out;
                        *p++ = *s++;
                }
index 85b9a3802850d8b81a2d3fb227fd60120be98390..14f8230d2f3e0707d5ee600f3b15a5baa92118a5 100644 (file)
@@ -3,7 +3,7 @@
    DHCP/BOOTP Relay Agent. */
 
 /*
- * Copyright(c) 2004-2017 by Internet Systems Consortium, Inc.("ISC")
+ * Copyright(c) 2004-2019 by Internet Systems Consortium, Inc.("ISC")
  * Copyright(c) 1997-2003 by Internet Software Consortium
  *
  * Permission to use, copy, modify, and distribute this software for any
@@ -1801,7 +1801,7 @@ void request_v4_interface(const char* name, int flags) {
                  (flags & INTERFACE_UPSTREAM ? 'Y' : 'N'),
                  (flags & INTERFACE_DOWNSTREAM ? 'Y' : 'N'));
 
-       strncpy(tmp->name, name, len);
-       interface_snorf(tmp, (INTERFACE_REQUESTED | flags));
-       interface_dereference(&tmp, MDL);
+        memcpy(tmp->name, name, len);
+        interface_snorf(tmp, (INTERFACE_REQUESTED | flags));
+        interface_dereference(&tmp, MDL);
 }
index 26fea5d7dee911ca69bb0fa17dc63eab84097809..ef411b6f7717a521c807a6dcf2822249e643123e 100644 (file)
@@ -3,7 +3,7 @@
    Parser for dhcpd config file... */
 
 /*
- * Copyright (c) 2004-2017 by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (c) 2004-2019 by Internet Systems Consortium, Inc. ("ISC")
  * Copyright (c) 1995-2003 by Internet Software Consortium
  *
  * Permission to use, copy, modify, and distribute this software for any
@@ -903,7 +903,7 @@ void parse_failover_peer (cfile, group, type)
        if (is_identifier (token) || token == STRING) {
                name = dmalloc (strlen (val) + 1, MDL);
                if (!name)
-                       log_fatal ("no memory for peer name %s", name);
+                       log_fatal ("no memory for peer name %s", val);
                strcpy (name, val);
        } else {
                parse_warn (cfile, "expecting failover peer name.");
@@ -1215,7 +1215,7 @@ void parse_failover_state_declaration (struct parse *cfile,
                        name = dmalloc (strlen (val) + 1, MDL);
                        if (!name)
                                log_fatal ("failover peer name %s: no memory",
-                                          name);
+                                          val);
                        strcpy (name, val);
                } else {
                        parse_warn (cfile, "expecting failover peer name.");