From: LIU Hao <lh_mouse@126.com>
To: libc-alpha@sourceware.org
Subject: `__if_nametoindex()` can leak an FD if its argument is too long
Date: Tue, 7 Feb 2023 21:11:42 +0800 [thread overview]
Message-ID: <162965eb-f84c-ca03-2cc1-dd895fbadcd6@126.com> (raw)
[-- 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 --]
reply other threads:[~2023-02-07 13:11 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=162965eb-f84c-ca03-2cc1-dd895fbadcd6@126.com \
--to=lh_mouse@126.com \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).