From dd85cb195879301035dd74b880c75c479cfb6c86 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 1 Feb 2022 15:35:47 +0100 Subject: [PATCH] dhcp: improve error message in assertion of NMDhcpOption data We have global data NMDhcpOption that describes the DHCP meta data. There is a consistency check with NM_MORE_ASSERTS. Improve the error message when the meta data is inconsistent to help finding the bug. --- src/core/dhcp/nm-dhcp-options.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/core/dhcp/nm-dhcp-options.c b/src/core/dhcp/nm-dhcp-options.c index ab64a67c1c..8e18156f09 100644 --- a/src/core/dhcp/nm-dhcp-options.c +++ b/src/core/dhcp/nm-dhcp-options.c @@ -247,7 +247,7 @@ _sorted_options_generate_sort(gconstpointer pa, gconstpointer pb, gpointer user_ const NMDhcpOption *const *b = pb; NM_CMP_DIRECT((*a)->option_num, (*b)->option_num); - return nm_assert_unreachable_val(0); + return 0; } static char * @@ -283,6 +283,16 @@ _ASSERT_sorted(int IS_IPv4, const NMDhcpOption *const *const sorted, int n) for (i = 0; i < n; i++) { const NMDhcpOption *opt = sorted[i]; + if (!opt || opt < options || opt >= &options[n]) { + g_error("%s:%d: _sorted_options_%c[%d] must be a valid pointer into " + "_nm_dhcp_option_dhcp%c_options, but is %p", + __FILE__, + __LINE__, + IS_IPv4 ? '4' : '6', + i, + IS_IPv4 ? '4' : '6', + opt); + } g_assert(opt); g_assert(opt >= options); g_assert(opt < &options[n]); @@ -291,7 +301,7 @@ _ASSERT_sorted(int IS_IPv4, const NMDhcpOption *const *const sorted, int n) const NMDhcpOption *opt2 = sorted[j]; if (opt == opt2) { - g_error("%s:%d: the _sorted_options_%c at [%d] (opt=%u, %s) is duplicated at " + g_error("%s:%d: _sorted_options_%c[%d] (opt=%u, %s) is duplicated at " "[%d] (SORT: %s)", __FILE__, __LINE__, @@ -308,7 +318,7 @@ _ASSERT_sorted(int IS_IPv4, const NMDhcpOption *const *const sorted, int n) const NMDhcpOption *opt2 = sorted[i - 1]; if (opt2->option_num >= opt->option_num) { - g_error("%s:%d: the _sorted_options_%c at [%d] (opt=%u, %s) should come before " + g_error("%s:%d: _sorted_options_%c[%d] (opt=%u, %s) should come before " "[%d] (opt=%u, %s) (SORT: %s)", __FILE__, __LINE__,