Format string bug

Maxim Dounin mdounin at mdounin.ru
Thu Jun 10 16:51:32 UTC 2021


Hello!

On Thu, Jun 10, 2021 at 11:07:39AM -0400, Jan Kasiak wrote:

> I think there is a bug in one of the format strings.
> 
> diff --git a/src/os/win32/ngx_win32_init.c b/src/os/win32/ngx_win32_init.c
> index 3249fb29..11941f62 100644
> --- a/src/os/win32/ngx_win32_init.c
> +++ b/src/os/win32/ngx_win32_init.c
> @@ -305,7 +305,7 @@ ngx_os_status(ngx_log_t *log)
>              /* Win9x build */
> 
>              ngx_log_error(NGX_LOG_INFO, log, 0,
> -                          "OS: %u build:%ud.%ud.%ud, \"%s\"",
> +                          "OS: %ud build:%ud.%ud.%ud, \"%s\"",
>                            ngx_win32_version,
>                            osvi.dwBuildNumber >> 24,
>                            (osvi.dwBuildNumber >> 16) & 0xff,

Yes, thanks.

Further, the "%ud" used elsewhere for ngx_win32_version is also incorrect,
given the ngx_uint_t type: it should be %ui instead.

The following patch fixes both issues:

# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1623342077 -10800
#      Thu Jun 10 19:21:17 2021 +0300
# Node ID f7120b838d9c7647a711e53166a6f0f2522b35da
# Parent  5f765427c17ac8cf753967387562201cf4f78dc4
Fixed format strings for ngx_win32_version.

diff --git a/src/os/win32/ngx_win32_init.c b/src/os/win32/ngx_win32_init.c
--- a/src/os/win32/ngx_win32_init.c
+++ b/src/os/win32/ngx_win32_init.c
@@ -295,7 +295,7 @@ ngx_os_status(ngx_log_t *log)
         osviex_stub = (ngx_osviex_stub_t *) &osvi.wServicePackMinor;
 
         ngx_log_error(NGX_LOG_INFO, log, 0,
-                      "OS: %ud build:%ud, \"%s\", suite:%Xd, type:%ud",
+                      "OS: %ui build:%ud, \"%s\", suite:%Xd, type:%ud",
                       ngx_win32_version, osvi.dwBuildNumber, osvi.szCSDVersion,
                       osviex_stub->wSuiteMask, osviex_stub->wProductType);
 
@@ -305,7 +305,7 @@ ngx_os_status(ngx_log_t *log)
             /* Win9x build */
 
             ngx_log_error(NGX_LOG_INFO, log, 0,
-                          "OS: %u build:%ud.%ud.%ud, \"%s\"",
+                          "OS: %ui build:%ud.%ud.%ud, \"%s\"",
                           ngx_win32_version,
                           osvi.dwBuildNumber >> 24,
                           (osvi.dwBuildNumber >> 16) & 0xff,
@@ -321,7 +321,7 @@ ngx_os_status(ngx_log_t *log)
              * and we do not support VER_PLATFORM_WIN32s at all
              */
 
-            ngx_log_error(NGX_LOG_INFO, log, 0, "OS: %ud build:%ud, \"%s\"",
+            ngx_log_error(NGX_LOG_INFO, log, 0, "OS: %ui build:%ud, \"%s\"",
                           ngx_win32_version, osvi.dwBuildNumber,
                           osvi.szCSDVersion);
         }



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


More information about the nginx-devel mailing list