[Bug 268436] [libc] syslog() and vsyslog() do not preserve the errno at the time of the call.

From: <bugzilla-noreply_at_freebsd.org>
Date: Sun, 18 Dec 2022 02:55:26 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=268436

            Bug ID: 268436
           Summary: [libc] syslog() and vsyslog() do not preserve the
                    errno at the time of the call.
           Product: Base System
           Version: Unspecified
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Many People
          Priority: ---
         Component: bin
          Assignee: bugs@FreeBSD.org
          Reporter: hodong@nimfsoft.art

Hello.

Since syslog() and vsyslog() do not preserve errno at the time of the call,
errno may change after calling syslog.

https://cgit.freebsd.org/src/tree/lib/libc/gen/syslog.c
https://github.com/freebsd/freebsd-src/blob/main/lib/libc/gen/syslog.c

I suggest this patch.

--- a/syslog.c
+++ b/syslog.c
@@ -348,7 +348,9 @@ vsyslog(int pri, const char *fmt, va_list ap)

        THREAD_LOCK();
        pthread_cleanup_push(syslog_cancel_cleanup, NULL);
+       int saved_errno = errno;
        vsyslog1(pri, fmt, ap);
+       errno = saved_errno;
        pthread_cleanup_pop(1);
 }

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