* `__if_nametoindex()` can leak an FD if its argument is too long
@ 2023-02-07 13:11 LIU Hao
0 siblings, 0 replies; only message in thread
From: LIU Hao @ 2023-02-07 13:11 UTC (permalink / raw)
To: libc-alpha
[-- Attachment #1.1.1: Type: text/plain, Size: 191 bytes --]
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
[-- Attachment #1.1.2: 0001-hurd-Don-t-lean-the-socket-FD-if-argument-to-__if_na.patch --]
[-- Type: text/x-patch, Size: 1013 bytes --]
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(-)
diff --git a/sysdeps/mach/hurd/if_index.c b/sysdeps/mach/hurd/if_index.c
index a4472269b7..9b598a279d 100644
--- a/sysdeps/mach/hurd/if_index.c
+++ b/sysdeps/mach/hurd/if_index.c
@@ -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
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-02-07 13:11 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-07 13:11 `__if_nametoindex()` can leak an FD if its argument is too long LIU Hao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).