[Bug 277906] libalias fails to report an error from dlsym()

From: <bugzilla-noreply_at_freebsd.org>
Date: Sat, 23 Mar 2024 12:53:06 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=277906

            Bug ID: 277906
           Summary: libalias fails to report an error from dlsym()
           Product: Base System
           Version: 14.0-RELEASE
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Some People
          Priority: ---
         Component: misc
          Assignee: bugs@FreeBSD.org
          Reporter: Igor.Gusarov@kaspersky.com

The following code can be found in file /usr/src/sys/netinet/libalias/alias.c
around line 1715

        p = dlsym(handle, "alias_mod");
        if ((error = dlerror()) != NULL)  {
                fprintf(stderr, "%s\n", dlerror());
                return (EINVAL);
        }

This code calls dlerror() function twice: first time to check if there is an
error, and the second time to print that error. Such approach is wrong, as
described in manual page for dlerror(3):

> At each call
> to dlerror(), the error indication is reset.  Thus in the case of two
> calls to dlerror(), where the second call follows the first immediately,
> the second call will always return a null pointer.

Which may result in the following not helpful error message when trying to
start natd:

# service natd restart
Stopping natd.
Waiting for PIDS: 23950.
Starting natd.
(null)                      <--- Here. This null message is printed at
alias.c:1715
# 

Suggested fix:
Apply the following patch to /usr/src/sys/netinet/libalias/alias.c

--- alias.c     2023-11-10 03:07:53.000000000 +0300
+++ alias.c.new 2024-03-23 15:48:15.335314000 +0300
@@ -1712,7 +1712,7 @@

        p = dlsym(handle, "alias_mod");
        if ((error = dlerror()) != NULL)  {
-               fprintf(stderr, "%s\n", dlerror());
+               fprintf(stderr, "%s\n", error);
                return (EINVAL);
        }

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