One more unsafe ngx_errno usage

Maxim Dounin mdounin at mdounin.ru
Wed May 13 13:21:43 UTC 2026


Hello!

On Wed, May 13, 2026 at 03:32:32PM +0930, David Pfitzner via nginx-devel wrote:

> A while ago there was this commit:
> https://freenginx.org/hg/nginx/rev/d596a1fb8b9c
> "Cleaned up unsafe ngx_errno and ngx_socket_errno usage."
> 
> I just noticed that one part of the above fix was incomplete. In
> src/os/unix/ngx_freebsd_init.c (tip) starting at line 125 we have:
> 
>     if (sysctlbyname("kern.osrelease",
>                      ngx_freebsd_kern_osrelease, &size, NULL, 0) == -1) {
>         err = ngx_errno;
> 
>         ngx_log_error(NGX_LOG_ALERT, log, err,
>                       "sysctlbyname(kern.osrelease) failed");
> 
>         if (ngx_errno != NGX_ENOMEM) {
>             return NGX_ERROR;
>         }
> 
> In the 'if' condition at the end, I think 'ngx_errno' should instead be
> 'err' (similar to the code block just previous). Sorry, I didn't create a
> patch, but the fix is simple.

Sure, thanks for catching this.
Just in case, the patch is below:

# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1778678442 -10800
#      Wed May 13 16:20:42 2026 +0300
# Node ID 5fec4281a4931de7888a7994ff1bd7f6d7254fb7
# Parent  207b425c3dba591ba7dcd9e5533ae20bb0e0caed
Fixed unsafe ngx_errno usage, missed in 9457:d596a1fb8b9c.

Reported by David Pfitzner.

diff --git a/src/os/unix/ngx_freebsd_init.c 
b/src/os/unix/ngx_freebsd_init.c
--- a/src/os/unix/ngx_freebsd_init.c
+++ b/src/os/unix/ngx_freebsd_init.c
@@ -129,7 +129,7 @@ ngx_os_specific_init(ngx_log_t *log)
         ngx_log_error(NGX_LOG_ALERT, log, err,
                       "sysctlbyname(kern.osrelease) failed");
 
-        if (ngx_errno != NGX_ENOMEM) {
+        if (err != NGX_ENOMEM) {
             return NGX_ERROR;
         }
 

-- 
Maxim Dounin
http://mdounin.ru/


More information about the nginx-devel mailing list