`__if_nametoindex()` can leak an FD if its argument is too long
Checks
Context |
Check |
Description |
dj/TryBot-apply_patch |
success
|
Patch applied to master at the time it was sent
|
dj/TryBot-32bit |
success
|
Build for i686
|
Commit Message
Greetings, libc maintainers.
It looks like `if_nametoindex()` for Hurd can leak a socket descriptor if its argument string is too
long. Patch attached.
--
Best regards,
LIU Hao
From 6ba2bc2fa7d01999a9c92953ca7d84146fe6c741 Mon Sep 17 00:00:00 2001
From: LIU Hao <lh_mouse@126.com>
Date: Tue, 7 Feb 2023 21:05:50 +0800
Subject: [PATCH] hurd: Don't lean the socket FD if argument to
`__if_nametoindex()` is too long
---
sysdeps/mach/hurd/if_index.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
@@ -32,10 +32,7 @@ unsigned int
__if_nametoindex (const char *ifname)
{
struct ifreq ifr;
- int fd = __socket (AF_INET, SOCK_DGRAM, 0);
-
- if (fd < 0)
- return 0;
+ int fd;
if (strlen (ifname) >= IFNAMSIZ)
{
@@ -43,6 +40,10 @@ __if_nametoindex (const char *ifname)
return 0;
}
+ fd = __socket (AF_INET, SOCK_DGRAM, 0);
+ if (fd < 0)
+ return 0;
+
strncpy (ifr.ifr_name, ifname, IFNAMSIZ);
if (__ioctl (fd, SIOCGIFINDEX, &ifr) < 0)
{
--
2.34.1