Add new test for if_nameindex and if_indextoname (RHEL-53909)
Resolves: RHEL-53909
This commit is contained in:
parent
c00c38ca9c
commit
dbdfa82884
148
glibc-RHEL-53909-1.patch
Normal file
148
glibc-RHEL-53909-1.patch
Normal file
@ -0,0 +1,148 @@
|
||||
commit 2eee835eca960c9d4119279804214b7a1ed5d156
|
||||
Author: DJ Delorie <dj@redhat.com>
|
||||
Date: Thu Aug 8 22:44:56 2024 -0400
|
||||
|
||||
inet: test if_nametoindex and if_indextoname
|
||||
|
||||
Tests for if_nameindex, if_name2index, and if_index2name
|
||||
|
||||
Tests that valid results are consistent.
|
||||
|
||||
Tests that invalid parameters fail correctly.
|
||||
|
||||
Reviewed-by: Florian Weimer <fweimer@redhat.com>
|
||||
|
||||
diff --git a/inet/Makefile b/inet/Makefile
|
||||
index ef6b94ed0b519d6d..dbdcea9e71fdd765 100644
|
||||
--- a/inet/Makefile
|
||||
+++ b/inet/Makefile
|
||||
@@ -136,6 +136,7 @@ tests := \
|
||||
tst-getni1 \
|
||||
tst-getni2 \
|
||||
tst-if_index-long \
|
||||
+ tst-if_nameindex \
|
||||
tst-inet6_rth \
|
||||
tst-network \
|
||||
tst-ntoa \
|
||||
diff --git a/inet/tst-if_nameindex.c b/inet/tst-if_nameindex.c
|
||||
new file mode 100644
|
||||
index 0000000000000000..b025cdb3a7c6b68c
|
||||
--- /dev/null
|
||||
+++ b/inet/tst-if_nameindex.c
|
||||
@@ -0,0 +1,116 @@
|
||||
+/* Tests for if_nameindex et al.
|
||||
+ Copyright (C) 2024 Free Software Foundation, Inc.
|
||||
+ This file is part of the GNU C Library.
|
||||
+
|
||||
+ The GNU C Library is free software; you can redistribute it and/or
|
||||
+ modify it under the terms of the GNU Lesser General Public
|
||||
+ License as published by the Free Software Foundation; either
|
||||
+ version 2.1 of the License, or (at your option) any later version.
|
||||
+
|
||||
+ The GNU C Library is distributed in the hope that it will be useful,
|
||||
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
+ Lesser General Public License for more details.
|
||||
+
|
||||
+ You should have received a copy of the GNU Lesser General Public
|
||||
+ License along with the GNU C Library; if not, see
|
||||
+ <https://www.gnu.org/licenses/>. */
|
||||
+
|
||||
+#include <stdlib.h>
|
||||
+#include <errno.h>
|
||||
+#include <net/if.h>
|
||||
+#include <netdb.h>
|
||||
+#include <string.h>
|
||||
+#include <support/check.h>
|
||||
+#include <support/descriptors.h>
|
||||
+#include <support/support.h>
|
||||
+
|
||||
+static char *buffer;
|
||||
+
|
||||
+static const char *test_names[] = {
|
||||
+ "testing",
|
||||
+ "invalid",
|
||||
+ "dont-match",
|
||||
+ "",
|
||||
+ "\001\001\001\177",
|
||||
+ NULL
|
||||
+};
|
||||
+
|
||||
+static void
|
||||
+checki (int i)
|
||||
+{
|
||||
+ char *ifname;
|
||||
+
|
||||
+ /* Test that a known-invalid index returns NULL. */
|
||||
+ /* BUFFER should not be accessed. */
|
||||
+
|
||||
+ printf ("Testing if_indextoname (%d) == NULL\n", i);
|
||||
+ ifname = if_indextoname (i, NULL);
|
||||
+ TEST_VERIFY (ifname == NULL);
|
||||
+ TEST_VERIFY (errno == ENXIO);
|
||||
+}
|
||||
+
|
||||
+static int
|
||||
+do_test (void)
|
||||
+{
|
||||
+ struct if_nameindex *if_ni, *ifp;
|
||||
+ int min_idx, max_idx, buflen = 0;
|
||||
+ int i;
|
||||
+
|
||||
+ if_ni = if_nameindex ();
|
||||
+ TEST_VERIFY (if_ni != NULL);
|
||||
+
|
||||
+ min_idx = max_idx = if_ni->if_index;
|
||||
+
|
||||
+ for (ifp = if_ni; !(ifp->if_index == 0 && ifp->if_name == NULL); ifp++)
|
||||
+ {
|
||||
+ printf ("%u: %s\n", ifp->if_index, ifp->if_name);
|
||||
+ if (ifp->if_index < min_idx)
|
||||
+ min_idx = ifp->if_index;
|
||||
+ if (ifp->if_index > max_idx)
|
||||
+ max_idx = ifp->if_index;
|
||||
+ if (strlen (ifp->if_name) + 1 > buflen)
|
||||
+ buflen = strlen (ifp->if_name) + 1;
|
||||
+ }
|
||||
+ buffer = (char *) xmalloc (buflen);
|
||||
+
|
||||
+ /* Check normal operation. */
|
||||
+ for (ifp = if_ni; !(ifp->if_index == 0 && ifp->if_name == NULL); ifp++)
|
||||
+ {
|
||||
+ unsigned int idx = if_nametoindex (ifp->if_name);
|
||||
+ TEST_VERIFY (idx == ifp->if_index);
|
||||
+
|
||||
+ char *fn = if_indextoname (ifp->if_index, buffer);
|
||||
+ TEST_VERIFY (strcmp (fn, ifp->if_name) == 0);
|
||||
+ }
|
||||
+
|
||||
+ for (i=-2; i<min_idx; i++)
|
||||
+ checki (i);
|
||||
+ for (i=max_idx+1; i<max_idx+3; i++)
|
||||
+ checki (i);
|
||||
+
|
||||
+ /* Check that a known-invalid name returns 0. */
|
||||
+
|
||||
+ for (i=0; test_names[i] != NULL; i++)
|
||||
+ {
|
||||
+ /* Make sure our "invalid" name is really invalid. */
|
||||
+ for (ifp = if_ni; !(ifp->if_index == 0 && ifp->if_name == NULL); ifp++)
|
||||
+ if (strcmp (test_names[i], ifp->if_name) == 0)
|
||||
+ goto not_this_one;
|
||||
+
|
||||
+ printf ("Testing if_nametoindex (%s) == 0\n", test_names[i]);
|
||||
+
|
||||
+ unsigned int idx = if_nametoindex (test_names[i]);
|
||||
+ TEST_VERIFY (idx == 0);
|
||||
+ TEST_VERIFY (errno == ENODEV);
|
||||
+
|
||||
+ not_this_one:
|
||||
+ }
|
||||
+
|
||||
+
|
||||
+ if_freenameindex (if_ni);
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+#include <support/test-driver.c>
|
||||
20
glibc-RHEL-53909-2.patch
Normal file
20
glibc-RHEL-53909-2.patch
Normal file
@ -0,0 +1,20 @@
|
||||
commit 79f44e1a47e87907fb8e97bbd098e01c4adc26a5
|
||||
Author: Florian Weimer <fweimer@redhat.com>
|
||||
Date: Mon Aug 26 16:45:31 2024 +0200
|
||||
|
||||
inet: Avoid label at end of compound statement in tst-if_nameindex
|
||||
|
||||
This fails to compile with GCC 8.
|
||||
|
||||
diff --git a/inet/tst-if_nameindex.c b/inet/tst-if_nameindex.c
|
||||
index b025cdb3a7c6b68c..5b905601245bef34 100644
|
||||
--- a/inet/tst-if_nameindex.c
|
||||
+++ b/inet/tst-if_nameindex.c
|
||||
@@ -105,6 +105,7 @@ do_test (void)
|
||||
TEST_VERIFY (errno == ENODEV);
|
||||
|
||||
not_this_one:
|
||||
+ ;
|
||||
}
|
||||
|
||||
|
||||
@ -157,7 +157,7 @@ end \
|
||||
Summary: The GNU libc libraries
|
||||
Name: glibc
|
||||
Version: %{glibcversion}
|
||||
Release: 208%{?dist}
|
||||
Release: 209%{?dist}
|
||||
|
||||
# In general, GPLv2+ is used by programs, LGPLv2+ is used for
|
||||
# libraries.
|
||||
@ -1252,6 +1252,8 @@ Patch943: glibc-RHEL-48820-4.patch
|
||||
Patch944: glibc-RHEL-48820-5.patch
|
||||
Patch945: glibc-RHEL-48820-6.patch
|
||||
Patch946: glibc-RHEL-48820-7.patch
|
||||
Patch947: glibc-RHEL-53909-1.patch
|
||||
Patch948: glibc-RHEL-53909-2.patch
|
||||
|
||||
##############################################################################
|
||||
# Continued list of core "glibc" package information:
|
||||
@ -3249,6 +3251,9 @@ update_gconv_modules_cache ()
|
||||
%endif
|
||||
|
||||
%changelog
|
||||
* Tue Jul 01 2025 Arjun Shankar <arjun@redhat.com> - 2.34-209
|
||||
- Add new test for if_nameindex and if_indextoname (RHEL-53909)
|
||||
|
||||
* Thu Jun 26 2025 Frédéric Bérat <fberat@redhat.com> - 2.34-208
|
||||
- Switch to main malloc after final ld.so self-relocation. (RHEL-48820)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user