[Bug 288931] gai_strerror() incorrectly modifies errno

From: <bugzilla-noreply_at_freebsd.org>
Date: Tue, 19 Aug 2025 01:07:03 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=288931

            Bug ID: 288931
           Summary: gai_strerror() incorrectly modifies errno
           Product: Base System
           Version: 14.3-RELEASE
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Some People
          Priority: ---
         Component: standards
          Assignee: standards@FreeBSD.org
          Reporter: chris.m.dunlap@gmail.com
 Attachment #263050 text/plain
         mime type:

Created attachment 263050
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=263050&action=edit
reproducer

The gai_strerror() function modifies errno even when called with valid input,
which violates standard library conventions.

Reproduction:
- Set errno to any value
- Call gai_strerror(0)
- errno is changed to EBADF (9)

This affects any code that needs to preserve errno across gai_strerror() calls.

$ uname -a
FreeBSD freebsd143 14.3-RELEASE-p2 FreeBSD 14.3-RELEASE-p2 GENERIC amd64

$ ./gai_strerror_resets_errno_test 
gai_strerror changed errno from 0 to 9 (Bad file descriptor)

-- 
You are receiving this mail because:
You are the assignee for the bug.