From 6ba2bc2fa7d01999a9c92953ca7d84146fe6c741 Mon Sep 17 00:00:00 2001 From: LIU Hao 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