From f0a926871840a4ae470abed52a8ef2caff8b1092 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 10 Feb 2021 09:26:41 +0100 Subject: [PATCH] dhcp: require options argument for nm_dhcp_option_add_option() It's not clear why the option argument would be optional. Also, it's not optional for nm_dhcp_option_take_option(). Add an nm_assert() to catch such wrong uses. --- src/core/dhcp/nm-dhcp-options.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/core/dhcp/nm-dhcp-options.c b/src/core/dhcp/nm-dhcp-options.c index 09dd6f363f..c10077a431 100644 --- a/src/core/dhcp/nm-dhcp-options.c +++ b/src/core/dhcp/nm-dhcp-options.c @@ -219,7 +219,12 @@ nm_dhcp_option_take_option(GHashTable * options, guint option, char * value) { - nm_assert(options); + if (!options) { + nm_assert_not_reached(); + g_free(value); + return; + } + nm_assert(requests); nm_assert(value); nm_assert(g_utf8_validate(value, -1, NULL)); @@ -233,8 +238,7 @@ nm_dhcp_option_add_option(GHashTable * options, guint option, const char * value) { - if (options) - nm_dhcp_option_take_option(options, requests, option, g_strdup(value)); + nm_dhcp_option_take_option(options, requests, option, g_strdup(value)); } void @@ -243,11 +247,10 @@ nm_dhcp_option_add_option_u64(GHashTable * options, guint option, guint64 value) { - if (options) - nm_dhcp_option_take_option(options, - requests, - option, - g_strdup_printf("%" G_GUINT64_FORMAT, value)); + nm_dhcp_option_take_option(options, + requests, + option, + g_strdup_printf("%" G_GUINT64_FORMAT, value)); } void @@ -255,8 +258,10 @@ nm_dhcp_option_add_requests_to_options(GHashTable *options, const NMDhcpOption * { guint i; - if (!options) + if (!options) { + nm_assert_not_reached(); return; + } for (i = 0; requests[i].name; i++) { if (requests[i].include)