public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug network/28001] New: getaddrinfo() set errno on no error
@ 2021-06-21 13:09 lego12239 at yandex dot ru
  2021-06-21 13:10 ` [Bug network/28001] " lego12239 at yandex dot ru
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: lego12239 at yandex dot ru @ 2021-06-21 13:09 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=28001

            Bug ID: 28001
           Summary: getaddrinfo() set errno on no error
           Product: glibc
           Version: 2.33
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: network
          Assignee: unassigned at sourceware dot org
          Reporter: lego12239 at yandex dot ru
  Target Milestone: ---

Created attachment 13506
  --> https://sourceware.org/bugzilla/attachment.cgi?id=13506&action=edit
t.c

If ipv6 link-local address is specified with a scope id as an index, then
getaddrinfo() set errno and return success. It looks like getaddrinfo() try to
get device index by scope id and in case when scope id is already a device
index corresponding ioctl() returns ENODEV and getaddrinfo() doesn't reset
errno after this.

Steps to reproduce:

1. Compile the code(t.c):
~$ cat t.c
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <arpa/inet.h>

void
main(int argc, char **argv)
{
        int ret;
        struct addrinfo hints, *res;
        char buf[1000];

        if (argc != 2)
                exit(1);

        printf("Before:\nerrno=%d(%s)\n", errno, strerror(errno));
        ret = getaddrinfo(argv[1], "5555", NULL, &res);
        printf("After:\nerrno=%d(%s), ret=%d\n", errno, strerror(errno), ret);
        for(; res; res = res->ai_next) {
                if (res->ai_family != AF_INET6) {
                        printf("entry: family is %d\n", res->ai_family);
                        continue;
                }
                inet_ntop(AF_INET6,
                  &((struct sockaddr_in6*)(res->ai_addr))->sin6_addr, buf,
                  1000);
                printf("entry: family is AF_INET6, addr is %s\n", buf);
        }
}
~$ gcc t.c

2. get device name, index and link-local ipv6 address(wlan0 in my case):
~$ ip a show dev wlan0
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
group default qlen 1000
    link/ether 38:59:f9:42:f6:63 brd ff:ff:ff:ff:ff:ff
    inet 192.168.255.222/24 brd 192.168.255.255 scope global noprefixroute
wlan0
       valid_lft forever preferred_lft forever
    inet6 fd01::2/64 scope global 
       valid_lft forever preferred_lft forever
    inet6 fe80::7657:bd53:daac:e55b/64 scope link 
       valid_lft forever preferred_lft forever

3. getaddrinfo() for ipv6:
~$ ./a.out fe80::7657:bd53:daac:e55b
Before:
errno=0(Success)
After:
errno=0(Success), ret=0
entry: family is AF_INET6, addr is fe80::7657:bd53:daac:e55b
entry: family is AF_INET6, addr is fe80::7657:bd53:daac:e55b
entry: family is AF_INET6, addr is fe80::7657:bd53:daac:e55b

4. getaddrinfo() for ipv6%IFNAME:
~$ ./a.out fe80::7657:bd53:daac:e55b%wlan0
Before:
errno=0(Success)
After:
errno=0(Success), ret=0
entry: family is AF_INET6, addr is fe80::7657:bd53:daac:e55b
entry: family is AF_INET6, addr is fe80::7657:bd53:daac:e55b
entry: family is AF_INET6, addr is fe80::7657:bd53:daac:e55b

5. getaddrinfo() for ipv6%IFIDX:
~$ ./a.out fe80::7657:bd53:daac:e55b%3
Before:
errno=0(Success)
After:
errno=19(No such device), ret=0
entry: family is AF_INET6, addr is fe80::7657:bd53:daac:e55b
entry: family is AF_INET6, addr is fe80::7657:bd53:daac:e55b
entry: family is AF_INET6, addr is fe80::7657:bd53:daac:e55b



~$ strace ./a.out fe80::7657:bd53:daac:e55b%wlan0 2>&1 | tail -n 15
access("/proc/net", R_OK)               = 0
access("/proc/net/unix", R_OK)          = 0
socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0) = 3
ioctl(3, SIOCGIFINDEX, {ifr_name="wlan0", ifr_ifindex=3}) = 0
close(3)                                = 0
write(1, "Before:\nerrno=0(Success)\nAfter:\n"..., 239Before:
errno=0(Success)
After:
errno=0(Success), ret=0
entry: family is AF_INET6, addr is fe80::7657:bd53:daac:e55b
entry: family is AF_INET6, addr is fe80::7657:bd53:daac:e55b
entry: family is AF_INET6, addr is fe80::7657:bd53:daac:e55b
) = 239
exit_group(0)                           = ?
+++ exited with 0 +++
~$ strace ./a.out fe80::7657:bd53:daac:e55b%3 2>&1 | tail -n 15
access("/proc/net", R_OK)               = 0
access("/proc/net/unix", R_OK)          = 0
socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0) = 3
ioctl(3, SIOCGIFINDEX, {ifr_name="3"})  = -1 ENODEV (No such device)
close(3)                                = 0
write(1, "Before:\nerrno=0(Success)\nAfter:\n"..., 247Before:
errno=0(Success)
After:
errno=19(No such device), ret=0
entry: family is AF_INET6, addr is fe80::7657:bd53:daac:e55b
entry: family is AF_INET6, addr is fe80::7657:bd53:daac:e55b
entry: family is AF_INET6, addr is fe80::7657:bd53:daac:e55b
) = 247
exit_group(0)                           = ?
+++ exited with 0 +++

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug network/28001] getaddrinfo() set errno on no error
  2021-06-21 13:09 [Bug network/28001] New: getaddrinfo() set errno on no error lego12239 at yandex dot ru
@ 2021-06-21 13:10 ` lego12239 at yandex dot ru
  2021-06-21 13:11 ` lego12239 at yandex dot ru
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: lego12239 at yandex dot ru @ 2021-06-21 13:10 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=28001

--- Comment #1 from Oleg <lego12239 at yandex dot ru> ---
Created attachment 13507
  --> https://sourceware.org/bugzilla/attachment.cgi?id=13507&action=edit
strace.wlan0.out

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug network/28001] getaddrinfo() set errno on no error
  2021-06-21 13:09 [Bug network/28001] New: getaddrinfo() set errno on no error lego12239 at yandex dot ru
  2021-06-21 13:10 ` [Bug network/28001] " lego12239 at yandex dot ru
@ 2021-06-21 13:11 ` lego12239 at yandex dot ru
  2021-06-21 13:11 ` lego12239 at yandex dot ru
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: lego12239 at yandex dot ru @ 2021-06-21 13:11 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=28001

--- Comment #2 from Oleg <lego12239 at yandex dot ru> ---
Created attachment 13508
  --> https://sourceware.org/bugzilla/attachment.cgi?id=13508&action=edit
strace.3.out

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug network/28001] getaddrinfo() set errno on no error
  2021-06-21 13:09 [Bug network/28001] New: getaddrinfo() set errno on no error lego12239 at yandex dot ru
  2021-06-21 13:10 ` [Bug network/28001] " lego12239 at yandex dot ru
  2021-06-21 13:11 ` lego12239 at yandex dot ru
@ 2021-06-21 13:11 ` lego12239 at yandex dot ru
  2021-06-21 13:45 ` schwab@linux-m68k.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: lego12239 at yandex dot ru @ 2021-06-21 13:11 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=28001

Oleg <lego12239 at yandex dot ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lego12239 at yandex dot ru

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug network/28001] getaddrinfo() set errno on no error
  2021-06-21 13:09 [Bug network/28001] New: getaddrinfo() set errno on no error lego12239 at yandex dot ru
                   ` (2 preceding siblings ...)
  2021-06-21 13:11 ` lego12239 at yandex dot ru
@ 2021-06-21 13:45 ` schwab@linux-m68k.org
  2021-06-21 14:01 ` lego12239 at yandex dot ru
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: schwab@linux-m68k.org @ 2021-06-21 13:45 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=28001

Andreas Schwab <schwab@linux-m68k.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |NOTABUG

--- Comment #3 from Andreas Schwab <schwab@linux-m68k.org> ---
getaddrinfo doesn't use errno for error reporting, thus its value is
unspecified.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug network/28001] getaddrinfo() set errno on no error
  2021-06-21 13:09 [Bug network/28001] New: getaddrinfo() set errno on no error lego12239 at yandex dot ru
                   ` (3 preceding siblings ...)
  2021-06-21 13:45 ` schwab@linux-m68k.org
@ 2021-06-21 14:01 ` lego12239 at yandex dot ru
  2021-06-21 14:03 ` lego12239 at yandex dot ru
  2021-06-21 14:11 ` schwab@linux-m68k.org
  6 siblings, 0 replies; 8+ messages in thread
From: lego12239 at yandex dot ru @ 2021-06-21 14:01 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=28001

Oleg <lego12239 at yandex dot ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|NOTABUG                     |FIXED

--- Comment #4 from Oleg <lego12239 at yandex dot ru> ---
Is this hard to set errno to 0 before return just for consistency?

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug network/28001] getaddrinfo() set errno on no error
  2021-06-21 13:09 [Bug network/28001] New: getaddrinfo() set errno on no error lego12239 at yandex dot ru
                   ` (4 preceding siblings ...)
  2021-06-21 14:01 ` lego12239 at yandex dot ru
@ 2021-06-21 14:03 ` lego12239 at yandex dot ru
  2021-06-21 14:11 ` schwab@linux-m68k.org
  6 siblings, 0 replies; 8+ messages in thread
From: lego12239 at yandex dot ru @ 2021-06-21 14:03 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=28001

--- Comment #5 from Oleg <lego12239 at yandex dot ru> ---
> getaddrinfo doesn't use errno for error reporting, thus its value is unspecified.

And this isn't true. getaddrinfo() use errno for error reporting in case when
return code is EAI_SYSTEM ;-).

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug network/28001] getaddrinfo() set errno on no error
  2021-06-21 13:09 [Bug network/28001] New: getaddrinfo() set errno on no error lego12239 at yandex dot ru
                   ` (5 preceding siblings ...)
  2021-06-21 14:03 ` lego12239 at yandex dot ru
@ 2021-06-21 14:11 ` schwab@linux-m68k.org
  6 siblings, 0 replies; 8+ messages in thread
From: schwab@linux-m68k.org @ 2021-06-21 14:11 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=28001

Andreas Schwab <schwab@linux-m68k.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|FIXED                       |NOTABUG

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-06-21 14:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-21 13:09 [Bug network/28001] New: getaddrinfo() set errno on no error lego12239 at yandex dot ru
2021-06-21 13:10 ` [Bug network/28001] " lego12239 at yandex dot ru
2021-06-21 13:11 ` lego12239 at yandex dot ru
2021-06-21 13:11 ` lego12239 at yandex dot ru
2021-06-21 13:45 ` schwab@linux-m68k.org
2021-06-21 14:01 ` lego12239 at yandex dot ru
2021-06-21 14:03 ` lego12239 at yandex dot ru
2021-06-21 14:11 ` schwab@linux-m68k.org

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).