1 /* Check for descriptor leak in if_nametoindex with a long interface name.
2 Copyright (C) 2018-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 /* This test checks for a descriptor leak in case of a long interface
20 name (CVE-2018-19591, bug 23927). */
26 #include <support/check.h>
27 #include <support/descriptors.h>
28 #include <support/support.h>
33 struct support_descriptors
*descrs
= support_descriptors_list ();
35 /* Prepare a name which is just as long as required for trigging the
37 char name
[IFNAMSIZ
+ 1];
38 memset (name
, 'A', IFNAMSIZ
);
39 name
[IFNAMSIZ
] = '\0';
40 TEST_COMPARE (strlen (name
), IFNAMSIZ
);
42 TEST_COMPARE (strlen (name
), sizeof (ifr
.ifr_name
));
44 /* Test directly via if_nametoindex. */
45 TEST_COMPARE (if_nametoindex (name
), 0);
46 TEST_COMPARE (errno
, ENODEV
);
47 support_descriptors_check (descrs
);
49 /* Same test via getaddrinfo. */
50 char *host
= xasprintf ("fea0::%%%s", name
);
51 struct addrinfo hints
= { .ai_flags
= AI_NUMERICHOST
, };
53 TEST_COMPARE (getaddrinfo (host
, NULL
, &hints
, &ai
), EAI_NONAME
);
54 support_descriptors_check (descrs
);
56 support_descriptors_free (descrs
);
61 #include <support/test-driver.c>