summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Markwalder <tmark@isc.org>2019-11-08 12:26:05 -0500
committerThomas Markwalder <tmark@isc.org>2019-11-08 12:26:05 -0500
commitb52f3de097afbd4411e1ef285c542557d3a98edd (patch)
tree169e3cd2627b0edb7d1a9f04237808e762a2914b
parentce2f66291cb4ddfec72803faa7391a4f58bfa5b2 (diff)
downloadisc-dhcp-b52f3de097afbd4411e1ef285c542557d3a98edd.tar.gz
[#15] Changes to eliminate errors and warnings under GCC 9
Merges changes for #15,!10 into v4_1_esv
-rw-r--r--RELNOTES6
-rw-r--r--common/discover.c4
-rw-r--r--common/parse.c24
-rw-r--r--common/tests/option_unittest.c142
-rw-r--r--includes/dhcpd.h3
-rw-r--r--includes/omapip/omapip_p.h3
-rw-r--r--omapip/errwarn.c17
-rw-r--r--relay/dhcrelay.c8
-rw-r--r--server/confpars.c6
9 files changed, 186 insertions, 27 deletions
diff --git a/RELNOTES b/RELNOTES
index eba2bf6a..7499c845 100644
--- 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
diff --git a/common/discover.c b/common/discover.c
index 706a08c1..d6115b34 100644
--- a/common/discover.c
+++ b/common/discover.c
@@ -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 */
diff --git a/common/parse.c b/common/parse.c
index 4b21c310..ff31e28c 100644
--- a/common/parse.c
+++ b/common/parse.c
@@ -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
index 00000000..cd52cfb4
--- /dev/null
+++ b/common/tests/option_unittest.c
@@ -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());
+}
diff --git a/includes/dhcpd.h b/includes/dhcpd.h
index d05dc759..6643dc4d 100644
--- a/includes/dhcpd.h
+++ b/includes/dhcpd.h
@@ -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
diff --git a/includes/omapip/omapip_p.h b/includes/omapip/omapip_p.h
index 8932f5df..4369410d 100644
--- a/includes/omapip/omapip_p.h
+++ b/includes/omapip/omapip_p.h
@@ -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);
diff --git a/omapip/errwarn.c b/omapip/errwarn.c
index a6ed209f..42a3fad2 100644
--- a/omapip/errwarn.c
+++ b/omapip/errwarn.c
@@ -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++;
}
diff --git a/relay/dhcrelay.c b/relay/dhcrelay.c
index 85b9a380..14f8230d 100644
--- a/relay/dhcrelay.c
+++ b/relay/dhcrelay.c
@@ -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);
}
diff --git a/server/confpars.c b/server/confpars.c
index 26fea5d7..ef411b6f 100644
--- a/server/confpars.c
+++ b/server/confpars.c
@@ -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.");