From 4192461fc896fc2c989c4a68c6456626325bef0a Mon Sep 17 00:00:00 2001 From: renmingshuai Date: Fri, 26 Nov 2021 19:25:58 +0800 Subject: [PATCH] fix coredump when client active is NULL, add lease time config ipv6, and add a test case to parse conde93 in option_unittest --- ...e-to-parse-code93-in-option_unittest.patch | 100 ++++++++++++++++++ dhcp.spec | 12 ++- feature-lease-time-config-ipv6.patch | 59 +++++++++++ fix-coredump-when-client-active-is-NULL.patch | 67 ++++++++++++ 4 files changed, 237 insertions(+), 1 deletion(-) create mode 100644 add-a-test-case-to-parse-code93-in-option_unittest.patch create mode 100644 feature-lease-time-config-ipv6.patch create mode 100644 fix-coredump-when-client-active-is-NULL.patch diff --git a/add-a-test-case-to-parse-code93-in-option_unittest.patch b/add-a-test-case-to-parse-code93-in-option_unittest.patch new file mode 100644 index 0000000..b1ae36c --- /dev/null +++ b/add-a-test-case-to-parse-code93-in-option_unittest.patch @@ -0,0 +1,100 @@ +From bd6db12aaeecbc4f76462b4016c7e74e43d532f3 Mon Sep 17 00:00:00 2001 +From: zhangqiumiao +Date: Tue, 10 Nov 2020 02:10:57 -0500 +Subject: [PATCH] add a test case to parse code93 in option_unittest + +--- + common/tests/option_unittest.c | 70 ++++++++++++++++++++++++++++++++++ + 1 file changed, 70 insertions(+) + +diff --git a/common/tests/option_unittest.c b/common/tests/option_unittest.c +index cd52cfb..0bb6517 100644 +--- a/common/tests/option_unittest.c ++++ b/common/tests/option_unittest.c +@@ -129,6 +129,75 @@ ATF_TC_BODY(pretty_print_option, tc) + } + } + ++ATF_TC(parse_code93_option); ++ ++ATF_TC_HEAD(parse_code93_option, tc) ++{ ++ atf_tc_set_md_var(tc, "descr", ++ "Verify that code93 can be parsed."); ++} ++ ++ATF_TC_BODY(parse_code93_option, tc) ++{ ++ struct option *option; ++ unsigned code; ++ unsigned char bad_data[32*1024]; ++ unsigned char good_data1[] = { 0,0 }; ++ unsigned char good_data2[] = { 0,7 }; ++ unsigned char good_data3[] = { 0,11 }; ++ 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 pxe-system-type and it happens to be format Sa */ ++ code = 93; ++ 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_data1, sizeof(good_data1), ++ emit_commas, emit_quotes); ++ ++ /* Make sure we get what we expect */ ++ if (!output_buf || strcmp(output_buf, "0")) { ++ atf_tc_fail("pretty_print_option 1 did not return \"\""); ++ } ++ ++ output_buf = pretty_print_option (option, good_data2, sizeof(good_data3), ++ emit_commas, emit_quotes); ++ /* Make sure we get what we expect */ ++ if (!output_buf || strcmp(output_buf, "7")) { ++ atf_tc_fail("pretty_print_option 2 did not return \"\""); ++ } ++ ++ output_buf = pretty_print_option (option, good_data3, sizeof(good_data3), ++ emit_commas, emit_quotes); ++ /* Make sure we get what we expect */ ++ if (!output_buf || strcmp(output_buf, "11")) { ++ atf_tc_fail("pretty_print_option 3 did not return \"\""); ++ } ++ ++ /* 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, "")) { ++ atf_tc_fail("pretty_print_option did not return \"\""); ++ } ++} + + /* This macro defines main() method that will call specified + test cases. tp and simple_test_case names can be whatever you want +@@ -137,6 +206,7 @@ ATF_TP_ADD_TCS(tp) + { + ATF_TP_ADD_TC(tp, option_refcnt); + ATF_TP_ADD_TC(tp, pretty_print_option); ++ ATF_TP_ADD_TC(tp, parse_code93_option); + + return (atf_no_error()); + } +-- +2.19.1 + diff --git a/dhcp.spec b/dhcp.spec index 53ba738..9c41463 100644 --- a/dhcp.spec +++ b/dhcp.spec @@ -3,7 +3,7 @@ Name: dhcp Version: 4.4.2 -Release: 8 +Release: 9 Summary: Dynamic host configuration protocol software #Please don't change the epoch on this package Epoch: 12 @@ -57,6 +57,10 @@ Patch35: CVE-2021-25217.patch Patch36: 0001-fix-multiple-definition-with-gcc-10.patch Patch37: 0002-fix-multiple-definition-with-gcc-10.patch +Patch38: fix-coredump-when-client-active-is-NULL.patch +Patch39: feature-lease-time-config-ipv6.patch +Patch40: add-a-test-case-to-parse-code93-in-option_unittest.patch + BuildRequires: gcc autoconf automake libtool openldap-devel krb5-devel libcap-ng-devel bind-export-devel BuildRequires: systemd systemd-devel @@ -292,6 +296,12 @@ exit 0 %{_mandir}/man3/omapi.3.gz %changelog +* Fri Nov 26 2021 renmingshuai - 4.4.2-9 +- Type:bugfix +- ID:NA +- SUG:restart +- DESC:fix coredump when client active is NULL, add lease time config ipv6 and add a unittest + * Tue Sep 14 2021 panchenbo - 4.4.2-8 - DESC: install dhcpd.conf.example diff --git a/feature-lease-time-config-ipv6.patch b/feature-lease-time-config-ipv6.patch new file mode 100644 index 0000000..0bcd431 --- /dev/null +++ b/feature-lease-time-config-ipv6.patch @@ -0,0 +1,59 @@ +From 8fb8c0fcd63917fc500fe6f14436234edc6677ed Mon Sep 17 00:00:00 2001 +From: majun +Date: Tue, 1 Sep 2020 11:50:17 +0800 +Subject: [PATCH] lease-time-config +Signed-off-by: majun + +--- + client/clparse.c | 5 +++++ + common/conflex.c | 3 +++ + includes/dhctoken.h | 3 ++- + 3 files changed, 10 insertions(+), 1 deletion(-) + +diff --git a/client/clparse.c b/client/clparse.c +index d445bae..d43e8ae 100644 +--- a/client/clparse.c ++++ b/client/clparse.c +@@ -453,6 +453,11 @@ void parse_client_statement (cfile, ip, config) + struct option ***append_list, **new_list, **cat_list; + + switch (peek_token (&val, (unsigned *)0, cfile)) { ++ case LEASE_TIME_IPV6: ++ skip_token(&val, (unsigned *)0, cfile); ++ parse_lease_time (cfile, &config -> requested_lease); ++ return; ++ + case INCLUDE: + skip_token(&val, (unsigned *)0, cfile); + token = next_token (&val, (unsigned *)0, cfile); +diff --git a/common/conflex.c b/common/conflex.c +index 71c0bf5..fa3acb8 100644 +--- a/common/conflex.c ++++ b/common/conflex.c +@@ -1146,6 +1146,9 @@ intern(char *atom, enum dhcp_token dfv) { + if (!strcasecmp (atom + 1, "ease-id-format")) { + return LEASE_ID_FORMAT; + } ++ if (!strcasecmp (atom + 1, "ease-time-ipv6")) { ++ return LEASE_TIME_IPV6; ++ } + break; + case 'm': + if (!strncasecmp (atom + 1, "ax", 2)) { +diff --git a/includes/dhctoken.h b/includes/dhctoken.h +index b4d93ba..0bc31ca 100644 +--- a/includes/dhctoken.h ++++ b/includes/dhctoken.h +@@ -378,7 +378,8 @@ enum dhcp_token { + TOKEN_OCTAL = 678, + KEY_ALGORITHM = 679, + BOOTP_BROADCAST_ALWAYS = 680, +- DESTINATION_DESCRIPTOR = 681 ++ DESTINATION_DESCRIPTOR = 681, ++ LEASE_TIME_IPV6 = 682 + }; + + #define is_identifier(x) ((x) >= FIRST_TOKEN && \ +-- +2.23.0 + diff --git a/fix-coredump-when-client-active-is-NULL.patch b/fix-coredump-when-client-active-is-NULL.patch new file mode 100644 index 0000000..ff42768 --- /dev/null +++ b/fix-coredump-when-client-active-is-NULL.patch @@ -0,0 +1,67 @@ +From 098d7f8e2e2b468e6a615084fb4330fed49bb54a Mon Sep 17 00:00:00 2001 +From: hanzhijun +Date: Mon, 24 Aug 2020 15:39:53 +0800 +Subject: [PATCH] fix coredump when client -> active is NULL + +--- + client/dhclient.c | 37 +++++++++++++++++++++++++++++++++++++ + 1 file changed, 37 insertions(+) + +diff --git a/client/dhclient.c b/client/dhclient.c +index 2a17bfd..7581670 100644 +--- a/client/dhclient.c ++++ b/client/dhclient.c +@@ -2059,6 +2059,24 @@ void state_bound (cpp) + struct data_string ds; + + ASSERT_STATE(state, S_BOUND); ++ if (!client -> active) ++ { ++ struct timeval tv; ++ ++ log_error ("No active lease in bound."); ++ script_init(client, "FAIL", (struct string_list *)0); ++ if (client -> alias) ++ script_write_params(client, "alias_", client -> alias); ++ script_go(client); ++ client -> state = S_INIT; ++ tv.tv_sec = cur_tv.tv_sec + ((client->config->retry_interval + 1) / 2 + ++ (random() % client->config->retry_interval)); ++ tv.tv_usec = ((tv.tv_sec - cur_tv.tv_sec) > 1) ? ++ random() % 1000000 : cur_tv.tv_usec; ++ add_timeout(&tv, state_init, client, 0, 0); ++ detach (); ++ return; ++ } + + /* T1 has expired. */ + make_request (client, client -> active); +@@ -3173,6 +3191,25 @@ void send_request (cpp) + return; + } + ++ if (!client -> active && client -> state != S_REQUESTING) ++ { ++ struct timeval tv; ++ ++ log_error ("No active lease in request."); ++ script_init(client, "FAIL", (struct string_list *)0); ++ if (client -> alias) ++ script_write_params(client, "alias_", client -> alias); ++ script_go(client); ++ client -> state = S_INIT; ++ tv.tv_sec = cur_tv.tv_sec + ((client->config->retry_interval + 1) / 2 + ++ (random() % client->config->retry_interval)); ++ tv.tv_usec = ((tv.tv_sec - cur_tv.tv_sec) > 1) ? ++ random() % 1000000 : cur_tv.tv_usec; ++ add_timeout(&tv, state_init, client, 0, 0); ++ detach (); ++ return; ++ } ++ + /* If we're in the reboot state, make sure the media is set up + correctly. */ + if (client -> state == S_REBOOTING && +-- +2.27.0 + -- Gitee