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: b...@freebsd.org
          Reporter: igor.gusa...@kaspersky.com

The following code can be found in file /usr/src/sys/netinet/libalias/aliasc
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.

Reply via email to