Re: [PATCH] Configure: fix "make install" when cross-compiling to Windows

2024-03-27 Thread Sergey Kandaurov

> On 28 Feb 2024, at 05:25, Piotr Sikora via nginx-devel 
>  wrote:
> 
> # HG changeset patch
> # User Piotr Sikora 
> # Date 1708977646 0
> #  Mon Feb 26 20:00:46 2024 +
> # Branch patch018
> # Node ID ea1ab31c166c52372b40429a1cccece9ec9e003b
> # Parent  dd95daa55cf6131a7e845edd6ad3b429bcef6f98
> Configure: fix "make install" when cross-compiling to Windows.
> 
> Signed-off-by: Piotr Sikora 


Both patches for crossbuilding on win32 pushed, thanks.

-- 
Sergey Kandaurov
___
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel


Re: [PATCH] Configure: add support for Homebrew on Apple Silicon

2024-03-27 Thread Sergey Kandaurov

> On 11 Mar 2024, at 19:14, Sergey Kandaurov  wrote:
> 
> 
>> On 8 Mar 2024, at 19:31, Piotr Sikora via nginx-devel 
>>  wrote:
>> 
>> Hi Sergey,
>> 
>>> An obvious question is why do you need this change.  Homebrew seems
>>> to be quite niche to pay attention.
>> 
>> Homebrew [1] is orders of magnitude more popular than MacPorts [2],
>> which is already supported by the configure script.
> 
> Thanks for clarifying this.
> 
>> 
>>> Using appropriate paths in
>>> --with-cc-opt / --with-ld-opt should work (not tested).
>> 
>> Everything under auto/lib can be replaced with --with-{cc,ld}-opt,
>> so I don't really understand this reasoning.
> 
> Given the high popularity, it may be indeed not an option.
> 
>> 
>>> A quick grep for MacPorts search paths suggests that some libraries
>>> are missing in the change.  If this is on purpose, please reflect
>>> this in the description.
>> 
>> libxml2, libxslt, and libexslt are all installed as part of Xcode,
>> which is required to use Homebrew and compile anything on macOS.
> 
> This raises a question whether we need to test it for MacPorts as well,
> which also requires SDK.  Obviously, it is out of scope of this patch.
> 
>> 
>> I'll ship update patch in a moment.
>> 
>>> Apple Silicon is something from the marketing language,
>>> using Apple ARM instead should be fine.
>>> 
>>> Notably, Homebrew uses Hardware::CPU.arm Ruby language boolean
>>> to make the distinction.
>> 
>> There is no such thing as "Apple ARM".
>> 
>> The official documentation uses the term "Apple silicon" [3],
>> Homebrew refers to the supported platform as "Apple Silicon" [4],
>> and Wikipedia has an article about "Apple silicon" [5].
> 
> Thank you for clarification.
> 
>> 
>>> Further, given the smooth decay on Intel-based hardware,
>>> I'd reduce this just to "Homebrew".
>> 
>> But that would be misleading, seeing that the new code path doesn't do
>> anything for Homebrew on Intel.
>> 
>> And then, there is Homebrew on Linux [6].
> 
> Given all the above argumentation, it makes sense
> to push the patch just as is.

Pushed, thanks.

-- 
Sergey Kandaurov
___
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel


Re: [PATCH] Configure: set cache line sizes for more architectures

2024-03-27 Thread Sergey Kandaurov

> On 28 Feb 2024, at 05:24, Piotr Sikora via nginx-devel 
>  wrote:
> 
> # HG changeset patch
> # User Piotr Sikora 
> # Date 1708977642 0
> #  Mon Feb 26 20:00:42 2024 +
> # Branch patch016
> # Node ID bb99cbe3a343ae581d2369b990aee66e69679ca2
> # Parent  f58bc1041ebca635517b919d58b49923bf24f76d
> Configure: set cache line sizes for more architectures.
> 
> Signed-off-by: Piotr Sikora 

Thanks for the patch.

> 
> diff -r f58bc1041ebc -r bb99cbe3a343 auto/os/conf
> --- a/auto/os/conf Mon Feb 26 20:00:40 2024 +
> +++ b/auto/os/conf Mon Feb 26 20:00:42 2024 +
> @@ -115,6 +115,21 @@
> NGX_MACH_CACHE_LINE=64
> ;;
> 
> +ppc64 | ppc64le)

This can be replaced with a wildcard.
Also, other systems may report a different value, e.g.:

$ grep -r MACHINE_ARCH sys/powerpc/include/param.h 
sys/powerpc/include/param.h:#ifndef MACHINE_ARCH
sys/powerpc/include/param.h:#define MACHINE_ARCH "powerpc64le"
sys/powerpc/include/param.h:#define MACHINE_ARCH "powerpc64"
sys/powerpc/include/param.h:#define MACHINE_ARCH "powerpcspe"
sys/powerpc/include/param.h:#define MACHINE_ARCH "powerpc"
sys/powerpc/include/param.h:#ifndef MACHINE_ARCH32
sys/powerpc/include/param.h:#define MACHINE_ARCH32 "powerpc"

As such, I pushed an updated version:
https://hg.nginx.org/nginx/rev/427aa785edf8

> +have=NGX_ALIGNMENT value=16 . auto/define
> +NGX_MACH_CACHE_LINE=128
> +;;
> +
> +riscv64)
> +have=NGX_ALIGNMENT value=16 . auto/define
> +NGX_MACH_CACHE_LINE=64
> +;;
> +
> +s390x)
> +have=NGX_ALIGNMENT value=16 . auto/define
> +NGX_MACH_CACHE_LINE=256
> +;;
> +
> *)
> have=NGX_ALIGNMENT value=16 . auto/define
> NGX_MACH_CACHE_LINE=32


-- 
Sergey Kandaurov
___
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel


Re: [PATCH] macOS: detect cache line size at runtime

2024-03-27 Thread Sergey Kandaurov

> On 21 Mar 2024, at 11:19, Piotr Sikora via nginx-devel 
>  wrote:
> 
> Hi Sergey,
> 
>> I prefer not to introduce more ad-hoc prefixes in the log summary.
>> Something like moving the "macOS" part to the end should be fine.
> 
> That's fine with me.
> 
>> style: this breaks a perfect indentation of two spaces after type;
>> further, it appears to be unsorted by type; I'd put it after u_long
> 
> Good catch, thanks!
> 
>> This makes the following slight update to the patch.
>> If you're okey with it, I will commit it then.
> 
> LGTM.
> 

Pushed the updated patch, thanks.

-- 
Sergey Kandaurov
___
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel


Re: [PATCH] Configure: link libcrypt when a feature using it is detected

2024-03-27 Thread Sergey Kandaurov

> On 21 Mar 2024, at 11:23, Piotr Sikora via nginx-devel 
>  wrote:
> 
> Hi Sergey,
> 
>> I'd rewrote the description to be more specific:
>> 
>> : Configure: fixed Linux crypt_r() test to add libcrypt.
>> :
>> : Previously, the resulting binary was successfully linked
>> : because libcrypt was added in a separate test for crypt().
> 
> That's fine with me.
> 
> Best regards,
> Piotr Sikora

Pushed with the updated description, thanks.

-- 
Sergey Kandaurov
___
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel


Re: [PATCH] Win32: fix unique file index calculations

2024-03-27 Thread Sergey Kandaurov

> On 28 Feb 2024, at 05:25, Piotr Sikora via nginx-devel 
>  wrote:
> 
> # HG changeset patch
> # User Piotr Sikora 
> # Date 1708977635 0
> #  Mon Feb 26 20:00:35 2024 +
> # Branch patch012
> # Node ID 04e3155b3b9651fee708898aaf82ac35532806ee
> # Parent  9b57470dc49f8d8d10abe30a5df628732d7618dc
> Win32: fix unique file index calculations.
> 
> The old code was breaking strict aliasing rules.
> 
> Signed-off-by: Piotr Sikora 
> 
> diff -r 9b57470dc49f -r 04e3155b3b96 src/os/win32/ngx_files.h
> --- a/src/os/win32/ngx_files.h Mon Feb 26 20:00:33 2024 +
> +++ b/src/os/win32/ngx_files.h Mon Feb 26 20:00:35 2024 +
> @@ -154,7 +154,8 @@
> (((off_t) (fi)->nFileSizeHigh << 32) | (fi)->nFileSizeLow)
> #define ngx_file_fs_size(fi)ngx_file_size(fi)
> 
> -#define ngx_file_uniq(fi)   (*(ngx_file_uniq_t *) &(fi)->nFileIndexHigh)
> +#define ngx_file_uniq(fi)
> \
> +(((ngx_file_uniq_t) (fi)->nFileIndexHigh << 32) | (fi)->nFileIndexLow)
> 
> 
> /* 1164447360 is commented in src/os/win32/ngx_time.c */

Pushed, thanks.

-- 
Sergey Kandaurov
___
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel


Re: [PATCH] Rewrite: fix "return" directive without response text

2024-03-27 Thread Sergey Kandaurov

> On 28 Feb 2024, at 05:21, Piotr Sikora via nginx-devel 
>  wrote:
> 
> # HG changeset patch
> # User Piotr Sikora 
> # Date 1708977628 0
> #  Mon Feb 26 20:00:28 2024 +
> # Branch patch008
> # Node ID 3cde11b747c08c69889edc014a700317fe4d1d88
> # Parent  5584232259d28489efba149f2f5ae730691ff0d4
> Rewrite: fix "return" directive without response text.
> 
> Previously, the response text wasn't initialized and the rewrite module
> was sending response body set to NULL.
> 
> Found with UndefinedBehaviorSanitizer (pointer-overflow).
> 
> Signed-off-by: Piotr Sikora 
> 
> diff -r 5584232259d2 -r 3cde11b747c0 
> src/http/modules/ngx_http_rewrite_module.c
> --- a/src/http/modules/ngx_http_rewrite_module.c Mon Feb 26 20:00:26 2024 
> +
> +++ b/src/http/modules/ngx_http_rewrite_module.c Mon Feb 26 20:00:28 2024 
> +
> @@ -489,6 +489,7 @@
> }
> 
> if (cf->args->nelts == 2) {
> +ngx_str_set(>text.value, "");
> return NGX_CONF_OK;
> }
> 

Pushed, thanks.

-- 
Sergey Kandaurov
___
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel


Re: [PATCH] Core: fix conversion of IPv4-mapped IPv6 addresses

2024-03-27 Thread Sergey Kandaurov

> On 21 Mar 2024, at 10:53, Piotr Sikora via nginx-devel 
>  wrote:
> 
> Hi Sergey,
> 
>> The "shift" remark doesn't describe a problem in details.
> 
> It's not a remark, it's the name of the UndefinedBehaviorSanitizer
> check that caught the issue [1].
> 

Thanks for clarification, restored.

>> @@ -507,7 +507,7 @@ ngx_cidr_match(struct sockaddr *sa, ngx_
>> 
>> p = inaddr6->s6_addr;
>> 
>> -inaddr = p[12] << 24;
>> +inaddr = (in_addr_t) p[12] << 24;
>> inaddr += p[13] << 16;
>> inaddr += p[14] << 8;
>> inaddr += p[15];
> 
> While this minimizes the diff and silences the error at hand,
> I find my version more readable.
> 
> But you're obviously welcome to commit either version.
> 
> [1] https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html
> 

Pushed with commit log refinements, thanks.

-- 
Sergey Kandaurov
___
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel


Re: [PATCH] Geo: fix uninitialized memory access

2024-03-27 Thread Sergey Kandaurov

> On 21 Mar 2024, at 10:44, Piotr Sikora via nginx-devel 
>  wrote:
> 
> Hi Roman,
> 
>> Thanks for the patch, looks valid, except we no longer need to explicitly
>> initialize fields to zero.
> 
> Right, I was going back-and-forth between which version I should send.
> 
>> Also, I think we need more details about the
>> uninitialized memory access.  See updated patch.
> 
> LGTM, thanks!
> 

Pushed, thanks.

-- 
Sergey Kandaurov
___
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel


[nginx] Configure: allow cross-compiling to Windows using Clang.

2024-03-27 Thread Sergey Kandaurov
details:   https://hg.nginx.org/nginx/rev/99e7050ac886
branches:  
changeset: 9235:99e7050ac886
user:  Piotr Sikora 
date:  Mon Feb 26 20:00:48 2024 +
description:
Configure: allow cross-compiling to Windows using Clang.

Signed-off-by: Piotr Sikora 

diffstat:

 auto/os/win32 |  2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diffs (12 lines):

diff -r c2e753d214b0 -r 99e7050ac886 auto/os/win32
--- a/auto/os/win32 Mon Feb 26 20:00:46 2024 +
+++ b/auto/os/win32 Mon Feb 26 20:00:48 2024 +
@@ -18,7 +18,7 @@ ngx_binext=".exe"
 
 case "$NGX_CC_NAME" in
 
-gcc)
+clang | gcc)
 CORE_LIBS="$CORE_LIBS -ladvapi32 -lws2_32"
 MAIN_LINK="$MAIN_LINK -Wl,--export-all-symbols"
 MAIN_LINK="$MAIN_LINK -Wl,--out-implib=$NGX_OBJS/libnginx.a"
___
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel


[nginx] Configure: fixed "make install" when cross-compiling to Windows.

2024-03-27 Thread Sergey Kandaurov
details:   https://hg.nginx.org/nginx/rev/c2e753d214b0
branches:  
changeset: 9234:c2e753d214b0
user:  Piotr Sikora 
date:  Mon Feb 26 20:00:46 2024 +
description:
Configure: fixed "make install" when cross-compiling to Windows.

Signed-off-by: Piotr Sikora 

diffstat:

 auto/install |  2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diffs (12 lines):

diff -r 398495d816f0 -r c2e753d214b0 auto/install
--- a/auto/install  Mon Feb 26 20:00:43 2024 +
+++ b/auto/install  Mon Feb 26 20:00:46 2024 +
@@ -112,7 +112,7 @@ install:build $NGX_INSTALL_PERL_MODULES
test ! -f '\$(DESTDIR)$NGX_SBIN_PATH' \\
|| mv '\$(DESTDIR)$NGX_SBIN_PATH' \\
'\$(DESTDIR)$NGX_SBIN_PATH.old'
-   cp $NGX_OBJS/nginx '\$(DESTDIR)$NGX_SBIN_PATH'
+   cp $NGX_OBJS/nginx$ngx_binext '\$(DESTDIR)$NGX_SBIN_PATH'
 
test -d '\$(DESTDIR)$NGX_CONF_PREFIX' \\
|| mkdir -p '\$(DESTDIR)$NGX_CONF_PREFIX'
___
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel


[nginx] Configure: added support for Homebrew on Apple Silicon.

2024-03-27 Thread Sergey Kandaurov
details:   https://hg.nginx.org/nginx/rev/398495d816f0
branches:  
changeset: 9233:398495d816f0
user:  Piotr Sikora 
date:  Mon Feb 26 20:00:43 2024 +
description:
Configure: added support for Homebrew on Apple Silicon.

Signed-off-by: Piotr Sikora 

diffstat:

 auto/lib/geoip/conf|  17 +
 auto/lib/google-perftools/conf |  16 
 auto/lib/libgd/conf|  17 +
 auto/lib/openssl/conf  |  18 ++
 auto/lib/pcre/conf |  16 
 5 files changed, 84 insertions(+), 0 deletions(-)

diffs (134 lines):

diff -r 427aa785edf8 -r 398495d816f0 auto/lib/geoip/conf
--- a/auto/lib/geoip/conf   Wed Mar 27 19:36:51 2024 +0400
+++ b/auto/lib/geoip/conf   Mon Feb 26 20:00:43 2024 +
@@ -64,6 +64,23 @@ if [ $ngx_found = no ]; then
 fi
 
 
+if [ $ngx_found = no ]; then
+
+# Homebrew on Apple Silicon
+
+ngx_feature="GeoIP library in /opt/homebrew/"
+ngx_feature_path="/opt/homebrew/include"
+
+if [ $NGX_RPATH = YES ]; then
+ngx_feature_libs="-R/opt/homebrew/lib -L/opt/homebrew/lib -lGeoIP"
+else
+ngx_feature_libs="-L/opt/homebrew/lib -lGeoIP"
+fi
+
+. auto/feature
+fi
+
+
 if [ $ngx_found = yes ]; then
 
 CORE_INCS="$CORE_INCS $ngx_feature_path"
diff -r 427aa785edf8 -r 398495d816f0 auto/lib/google-perftools/conf
--- a/auto/lib/google-perftools/confWed Mar 27 19:36:51 2024 +0400
+++ b/auto/lib/google-perftools/confMon Feb 26 20:00:43 2024 +
@@ -46,6 +46,22 @@ if [ $ngx_found = no ]; then
 fi
 
 
+if [ $ngx_found = no ]; then
+
+# Homebrew on Apple Silicon
+
+ngx_feature="Google perftools in /opt/homebrew/"
+
+if [ $NGX_RPATH = YES ]; then
+ngx_feature_libs="-R/opt/homebrew/lib -L/opt/homebrew/lib -lprofiler"
+else
+ngx_feature_libs="-L/opt/homebrew/lib -lprofiler"
+fi
+
+. auto/feature
+fi
+
+
 if [ $ngx_found = yes ]; then
 CORE_LIBS="$CORE_LIBS $ngx_feature_libs"
 
diff -r 427aa785edf8 -r 398495d816f0 auto/lib/libgd/conf
--- a/auto/lib/libgd/conf   Wed Mar 27 19:36:51 2024 +0400
+++ b/auto/lib/libgd/conf   Mon Feb 26 20:00:43 2024 +
@@ -65,6 +65,23 @@ if [ $ngx_found = no ]; then
 fi
 
 
+if [ $ngx_found = no ]; then
+
+# Homebrew on Apple Silicon
+
+ngx_feature="GD library in /opt/homebrew/"
+ngx_feature_path="/opt/homebrew/include"
+
+if [ $NGX_RPATH = YES ]; then
+ngx_feature_libs="-R/opt/homebrew/lib -L/opt/homebrew/lib -lgd"
+else
+ngx_feature_libs="-L/opt/homebrew/lib -lgd"
+fi
+
+. auto/feature
+fi
+
+
 if [ $ngx_found = yes ]; then
 
 CORE_INCS="$CORE_INCS $ngx_feature_path"
diff -r 427aa785edf8 -r 398495d816f0 auto/lib/openssl/conf
--- a/auto/lib/openssl/conf Wed Mar 27 19:36:51 2024 +0400
+++ b/auto/lib/openssl/conf Mon Feb 26 20:00:43 2024 +
@@ -122,6 +122,24 @@ else
 . auto/feature
 fi
 
+if [ $ngx_found = no ]; then
+
+# Homebrew on Apple Silicon
+
+ngx_feature="OpenSSL library in /opt/homebrew/"
+ngx_feature_path="/opt/homebrew/include"
+
+if [ $NGX_RPATH = YES ]; then
+ngx_feature_libs="-R/opt/homebrew/lib -L/opt/homebrew/lib 
-lssl -lcrypto"
+else
+ngx_feature_libs="-L/opt/homebrew/lib -lssl -lcrypto"
+fi
+
+ngx_feature_libs="$ngx_feature_libs $NGX_LIBDL $NGX_LIBPTHREAD"
+
+. auto/feature
+fi
+
 if [ $ngx_found = yes ]; then
 have=NGX_SSL . auto/have
 CORE_INCS="$CORE_INCS $ngx_feature_path"
diff -r 427aa785edf8 -r 398495d816f0 auto/lib/pcre/conf
--- a/auto/lib/pcre/confWed Mar 27 19:36:51 2024 +0400
+++ b/auto/lib/pcre/confMon Feb 26 20:00:43 2024 +
@@ -182,6 +182,22 @@ else
 . auto/feature
 fi
 
+if [ $ngx_found = no ]; then
+
+# Homebrew on Apple Silicon
+
+ngx_feature="PCRE library in /opt/homebrew/"
+ngx_feature_path="/opt/homebrew/include"
+
+if [ $NGX_RPATH = YES ]; then
+ngx_feature_libs="-R/opt/homebrew/lib -L/opt/homebrew/lib 
-lpcre"
+else
+ngx_feature_libs="-L/opt/homebrew/lib -lpcre"
+fi
+
+. auto/feature
+fi
+
 if [ $ngx_found = yes ]; then
 CORE_INCS="$CORE_INCS $ngx_feature_path"
 CORE_LIBS="$CORE_LIBS $ngx_feature_libs"
___
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel


[nginx] Configure: set cache line size for more architectures.

2024-03-27 Thread Sergey Kandaurov
details:   https://hg.nginx.org/nginx/rev/427aa785edf8
branches:  
changeset: 9232:427aa785edf8
user:  Sergey Kandaurov 
date:  Wed Mar 27 19:36:51 2024 +0400
description:
Configure: set cache line size for more architectures.

Based on a patch by Piotr Sikora.

diffstat:

 auto/os/conf |  15 +++
 1 files changed, 15 insertions(+), 0 deletions(-)

diffs (25 lines):

diff -r 61cd12c25878 -r 427aa785edf8 auto/os/conf
--- a/auto/os/conf  Mon Feb 26 20:00:40 2024 +
+++ b/auto/os/conf  Wed Mar 27 19:36:51 2024 +0400
@@ -115,6 +115,21 @@ case "$NGX_MACHINE" in
 NGX_MACH_CACHE_LINE=64
 ;;
 
+ppc64* | powerpc64*)
+have=NGX_ALIGNMENT value=16 . auto/define
+NGX_MACH_CACHE_LINE=128
+;;
+
+riscv64)
+have=NGX_ALIGNMENT value=16 . auto/define
+NGX_MACH_CACHE_LINE=64
+;;
+
+s390x)
+have=NGX_ALIGNMENT value=16 . auto/define
+NGX_MACH_CACHE_LINE=256
+;;
+
 *)
 have=NGX_ALIGNMENT value=16 . auto/define
 NGX_MACH_CACHE_LINE=32
___
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel


[nginx] Detect cache line size at runtime on macOS.

2024-03-27 Thread Sergey Kandaurov
details:   https://hg.nginx.org/nginx/rev/61cd12c25878
branches:  
changeset: 9231:61cd12c25878
user:  Piotr Sikora 
date:  Mon Feb 26 20:00:40 2024 +
description:
Detect cache line size at runtime on macOS.

Notably, Apple Silicon CPUs have 128 byte cache line size,
which is twice the default configured for generic aarch64.

Signed-off-by: Piotr Sikora 

diffstat:

 src/os/unix/ngx_darwin_init.c |  16 +++-
 src/os/unix/ngx_posix_init.c  |   5 -
 2 files changed, 15 insertions(+), 6 deletions(-)

diffs (55 lines):

diff -r fb989e24c60a -r 61cd12c25878 src/os/unix/ngx_darwin_init.c
--- a/src/os/unix/ngx_darwin_init.c Mon Feb 26 20:00:38 2024 +
+++ b/src/os/unix/ngx_darwin_init.c Mon Feb 26 20:00:40 2024 +
@@ -9,11 +9,12 @@
 #include 
 
 
-charngx_darwin_kern_ostype[16];
-charngx_darwin_kern_osrelease[128];
-int ngx_darwin_hw_ncpu;
-int ngx_darwin_kern_ipc_somaxconn;
-u_long  ngx_darwin_net_inet_tcp_sendspace;
+char ngx_darwin_kern_ostype[16];
+char ngx_darwin_kern_osrelease[128];
+int  ngx_darwin_hw_ncpu;
+int  ngx_darwin_kern_ipc_somaxconn;
+u_long   ngx_darwin_net_inet_tcp_sendspace;
+int64_t  ngx_darwin_hw_cachelinesize;
 
 ngx_uint_t  ngx_debug_malloc;
 
@@ -56,6 +57,10 @@ sysctl_t sysctls[] = {
   _darwin_kern_ipc_somaxconn,
   sizeof(ngx_darwin_kern_ipc_somaxconn), 0 },
 
+{ "hw.cachelinesize",
+  _darwin_hw_cachelinesize,
+  sizeof(ngx_darwin_hw_cachelinesize), 0 },
+
 { NULL, NULL, 0, 0 }
 };
 
@@ -155,6 +160,7 @@ ngx_os_specific_init(ngx_log_t *log)
 return NGX_ERROR;
 }
 
+ngx_cacheline_size = ngx_darwin_hw_cachelinesize;
 ngx_ncpu = ngx_darwin_hw_ncpu;
 
 if (ngx_darwin_kern_ipc_somaxconn > 32767) {
diff -r fb989e24c60a -r 61cd12c25878 src/os/unix/ngx_posix_init.c
--- a/src/os/unix/ngx_posix_init.c  Mon Feb 26 20:00:38 2024 +
+++ b/src/os/unix/ngx_posix_init.c  Mon Feb 26 20:00:40 2024 +
@@ -51,7 +51,10 @@ ngx_os_init(ngx_log_t *log)
 }
 
 ngx_pagesize = getpagesize();
-ngx_cacheline_size = NGX_CPU_CACHE_LINE;
+
+if (ngx_cacheline_size == 0) {
+ngx_cacheline_size = NGX_CPU_CACHE_LINE;
+}
 
 for (n = ngx_pagesize; n >>= 1; ngx_pagesize_shift++) { /* void */ }
 
___
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel


[nginx] Configure: fixed Linux crypt_r() test to add libcrypt.

2024-03-27 Thread Sergey Kandaurov
details:   https://hg.nginx.org/nginx/rev/fb989e24c60a
branches:  
changeset: 9230:fb989e24c60a
user:  Sergey Kandaurov 
date:  Mon Feb 26 20:00:38 2024 +
description:
Configure: fixed Linux crypt_r() test to add libcrypt.

Previously, the resulting binary was successfully linked
because libcrypt was added in a separate test for crypt().

Patch by Piotr Sikora.

diffstat:

 auto/os/linux |  4 
 1 files changed, 4 insertions(+), 0 deletions(-)

diffs (14 lines):

diff -r 000e2ded0a51 -r fb989e24c60a auto/os/linux
--- a/auto/os/linux Mon Feb 26 20:00:35 2024 +
+++ b/auto/os/linux Mon Feb 26 20:00:38 2024 +
@@ -228,6 +228,10 @@ ngx_feature_test="struct crypt_data  cd;
   crypt_r(\"key\", \"salt\", );"
 . auto/feature
 
+if [ $ngx_found = yes ]; then
+CRYPT_LIB="-lcrypt"
+fi
+
 
 ngx_include="sys/vfs.h"; . auto/include
 
___
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel


[nginx] Win32: fixed unique file index calculations.

2024-03-27 Thread Sergey Kandaurov
details:   https://hg.nginx.org/nginx/rev/000e2ded0a51
branches:  
changeset: 9229:000e2ded0a51
user:  Piotr Sikora 
date:  Mon Feb 26 20:00:35 2024 +
description:
Win32: fixed unique file index calculations.

The old code was breaking strict aliasing rules.

Signed-off-by: Piotr Sikora 

diffstat:

 src/os/win32/ngx_files.h |  3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diffs (13 lines):

diff -r dd4a570ff4ac -r 000e2ded0a51 src/os/win32/ngx_files.h
--- a/src/os/win32/ngx_files.h  Mon Feb 26 20:00:28 2024 +
+++ b/src/os/win32/ngx_files.h  Mon Feb 26 20:00:35 2024 +
@@ -154,7 +154,8 @@ ngx_int_t ngx_file_info(u_char *filename
 (((off_t) (fi)->nFileSizeHigh << 32) | (fi)->nFileSizeLow)
 #define ngx_file_fs_size(fi)ngx_file_size(fi)
 
-#define ngx_file_uniq(fi)   (*(ngx_file_uniq_t *) &(fi)->nFileIndexHigh)
+#define ngx_file_uniq(fi)\
+(((ngx_file_uniq_t) (fi)->nFileIndexHigh << 32) | (fi)->nFileIndexLow)
 
 
 /* 1164447360 is commented in src/os/win32/ngx_time.c */
___
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel


[nginx] Rewrite: fixed "return" directive without response text.

2024-03-27 Thread Sergey Kandaurov
details:   https://hg.nginx.org/nginx/rev/dd4a570ff4ac
branches:  
changeset: 9228:dd4a570ff4ac
user:  Piotr Sikora 
date:  Mon Feb 26 20:00:28 2024 +
description:
Rewrite: fixed "return" directive without response text.

Previously, the response text wasn't initialized and the rewrite module
was sending response body set to NULL.

Found with UndefinedBehaviorSanitizer (pointer-overflow).

Signed-off-by: Piotr Sikora 

diffstat:

 src/http/modules/ngx_http_rewrite_module.c |  1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diffs (11 lines):

diff -r f208413f307f -r dd4a570ff4ac src/http/modules/ngx_http_rewrite_module.c
--- a/src/http/modules/ngx_http_rewrite_module.cMon Mar 18 17:14:30 
2024 +0400
+++ b/src/http/modules/ngx_http_rewrite_module.cMon Feb 26 20:00:28 
2024 +
@@ -489,6 +489,7 @@ ngx_http_rewrite_return(ngx_conf_t *cf, 
 }
 
 if (cf->args->nelts == 2) {
+ngx_str_set(>text.value, "");
 return NGX_CONF_OK;
 }
 
___
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel


[nginx] Fixed undefined behaviour with IPv4-mapped IPv6 addresses.

2024-03-27 Thread Sergey Kandaurov
details:   https://hg.nginx.org/nginx/rev/f208413f307f
branches:  
changeset: 9227:f208413f307f
user:  Sergey Kandaurov 
date:  Mon Mar 18 17:14:30 2024 +0400
description:
Fixed undefined behaviour with IPv4-mapped IPv6 addresses.

Previously, it could result when left-shifting signed integer due to implicit
integer promotion, such that the most significant bit appeared on the sign bit.

In practice, though, this results in the same left value as with an explicit
cast, at least on known compilers, such as GCC and Clang.  The reason is that
in_addr_t, which is equivalent to uint32_t and same as "unsigned int" in ILP32
and LP64 data type models, has the same type width as the intermediate after
integer promotion, so there's no side effects such as sign-extension.  This
explains why adding an explicit cast does not change object files in practice.

Found with UndefinedBehaviorSanitizer (shift).

Based on a patch by Piotr Sikora.

diffstat:

 src/core/ngx_inet.c   |  2 +-
 src/http/modules/ngx_http_access_module.c |  2 +-
 src/http/modules/ngx_http_geo_module.c|  4 ++--
 src/http/modules/ngx_http_geoip_module.c  |  2 +-
 src/stream/ngx_stream_access_module.c |  2 +-
 src/stream/ngx_stream_geo_module.c|  4 ++--
 src/stream/ngx_stream_geoip_module.c  |  2 +-
 7 files changed, 9 insertions(+), 9 deletions(-)

diffs (102 lines):

diff -r 687c8306746f -r f208413f307f src/core/ngx_inet.c
--- a/src/core/ngx_inet.c   Thu Mar 14 18:37:20 2024 +0400
+++ b/src/core/ngx_inet.c   Mon Mar 18 17:14:30 2024 +0400
@@ -507,7 +507,7 @@ ngx_cidr_match(struct sockaddr *sa, ngx_
 
 p = inaddr6->s6_addr;
 
-inaddr = p[12] << 24;
+inaddr = (in_addr_t) p[12] << 24;
 inaddr += p[13] << 16;
 inaddr += p[14] << 8;
 inaddr += p[15];
diff -r 687c8306746f -r f208413f307f src/http/modules/ngx_http_access_module.c
--- a/src/http/modules/ngx_http_access_module.c Thu Mar 14 18:37:20 2024 +0400
+++ b/src/http/modules/ngx_http_access_module.c Mon Mar 18 17:14:30 2024 +0400
@@ -148,7 +148,7 @@ ngx_http_access_handler(ngx_http_request
 p = sin6->sin6_addr.s6_addr;
 
 if (alcf->rules && IN6_IS_ADDR_V4MAPPED(>sin6_addr)) {
-addr = p[12] << 24;
+addr = (in_addr_t) p[12] << 24;
 addr += p[13] << 16;
 addr += p[14] << 8;
 addr += p[15];
diff -r 687c8306746f -r f208413f307f src/http/modules/ngx_http_geo_module.c
--- a/src/http/modules/ngx_http_geo_module.cThu Mar 14 18:37:20 2024 +0400
+++ b/src/http/modules/ngx_http_geo_module.cMon Mar 18 17:14:30 2024 +0400
@@ -199,7 +199,7 @@ ngx_http_geo_cidr_variable(ngx_http_requ
 p = inaddr6->s6_addr;
 
 if (IN6_IS_ADDR_V4MAPPED(inaddr6)) {
-inaddr = p[12] << 24;
+inaddr = (in_addr_t) p[12] << 24;
 inaddr += p[13] << 16;
 inaddr += p[14] << 8;
 inaddr += p[15];
@@ -272,7 +272,7 @@ ngx_http_geo_range_variable(ngx_http_req
 if (IN6_IS_ADDR_V4MAPPED(inaddr6)) {
 p = inaddr6->s6_addr;
 
-inaddr = p[12] << 24;
+inaddr = (in_addr_t) p[12] << 24;
 inaddr += p[13] << 16;
 inaddr += p[14] << 8;
 inaddr += p[15];
diff -r 687c8306746f -r f208413f307f src/http/modules/ngx_http_geoip_module.c
--- a/src/http/modules/ngx_http_geoip_module.c  Thu Mar 14 18:37:20 2024 +0400
+++ b/src/http/modules/ngx_http_geoip_module.c  Mon Mar 18 17:14:30 2024 +0400
@@ -266,7 +266,7 @@ ngx_http_geoip_addr(ngx_http_request_t *
 if (IN6_IS_ADDR_V4MAPPED(inaddr6)) {
 p = inaddr6->s6_addr;
 
-inaddr = p[12] << 24;
+inaddr = (in_addr_t) p[12] << 24;
 inaddr += p[13] << 16;
 inaddr += p[14] << 8;
 inaddr += p[15];
diff -r 687c8306746f -r f208413f307f src/stream/ngx_stream_access_module.c
--- a/src/stream/ngx_stream_access_module.c Thu Mar 14 18:37:20 2024 +0400
+++ b/src/stream/ngx_stream_access_module.c Mon Mar 18 17:14:30 2024 +0400
@@ -144,7 +144,7 @@ ngx_stream_access_handler(ngx_stream_ses
 p = sin6->sin6_addr.s6_addr;
 
 if (ascf->rules && IN6_IS_ADDR_V4MAPPED(>sin6_addr)) {
-addr = p[12] << 24;
+addr = (in_addr_t) p[12] << 24;
 addr += p[13] << 16;
 addr += p[14] << 8;
 addr += p[15];
diff -r 687c8306746f -r f208413f307f src/stream/ngx_stream_geo_module.c
--- a/src/stream/ngx_stream_geo_module.cThu Mar 14 18:37:20 2024 +0400
+++ b/src/stream/ngx_stream_geo_module.cMon Mar 18 17:14:30 2024 +0400
@@ -190,7 +190,7 @@ ngx_stream_geo_cidr_variable(ngx_stream_
 p = inaddr6->s6_addr;
 
 if (IN6_IS_ADDR_V4MAPPED(inaddr6)) {
-inaddr = p[12] << 24;
+inaddr = (in_addr_t) p[12] << 24;
 inaddr += p[13] << 16;
 inaddr += p[14] << 

[nginx] Geo: fixed uninitialized memory access.

2024-03-27 Thread Sergey Kandaurov
details:   https://hg.nginx.org/nginx/rev/687c8306746f
branches:  
changeset: 9226:687c8306746f
user:  Piotr Sikora 
date:  Thu Mar 14 18:37:20 2024 +0400
description:
Geo: fixed uninitialized memory access.

While copying ngx_http_variable_value_t structures to geo binary base
in ngx_http_geo_copy_values(), and similarly in the stream module,
uninitialized parts of these structures are copied as well.  These
include the "escape" field and possible holes.  Calculating crc32 of
this data triggers uninitialized memory access.

Found with MemorySanitizer.

Signed-off-by: Piotr Sikora 

diffstat:

 src/http/modules/ngx_http_geo_module.c |  4 +---
 src/stream/ngx_stream_geo_module.c |  4 +---
 2 files changed, 2 insertions(+), 6 deletions(-)

diffs (42 lines):

diff -r 96ff3f8b7e50 -r 687c8306746f src/http/modules/ngx_http_geo_module.c
--- a/src/http/modules/ngx_http_geo_module.cFri Mar 22 18:39:50 2024 +0400
+++ b/src/http/modules/ngx_http_geo_module.cThu Mar 14 18:37:20 2024 +0400
@@ -1259,7 +1259,7 @@ ngx_http_geo_value(ngx_conf_t *cf, ngx_h
 return gvvn->value;
 }
 
-val = ngx_palloc(ctx->pool, sizeof(ngx_http_variable_value_t));
+val = ngx_pcalloc(ctx->pool, sizeof(ngx_http_variable_value_t));
 if (val == NULL) {
 return NULL;
 }
@@ -1271,8 +1271,6 @@ ngx_http_geo_value(ngx_conf_t *cf, ngx_h
 }
 
 val->valid = 1;
-val->no_cacheable = 0;
-val->not_found = 0;
 
 gvvn = ngx_palloc(ctx->temp_pool,
   sizeof(ngx_http_geo_variable_value_node_t));
diff -r 96ff3f8b7e50 -r 687c8306746f src/stream/ngx_stream_geo_module.c
--- a/src/stream/ngx_stream_geo_module.cFri Mar 22 18:39:50 2024 +0400
+++ b/src/stream/ngx_stream_geo_module.cThu Mar 14 18:37:20 2024 +0400
@@ -1209,7 +1209,7 @@ ngx_stream_geo_value(ngx_conf_t *cf, ngx
 return gvvn->value;
 }
 
-val = ngx_palloc(ctx->pool, sizeof(ngx_stream_variable_value_t));
+val = ngx_pcalloc(ctx->pool, sizeof(ngx_stream_variable_value_t));
 if (val == NULL) {
 return NULL;
 }
@@ -1221,8 +1221,6 @@ ngx_stream_geo_value(ngx_conf_t *cf, ngx
 }
 
 val->valid = 1;
-val->no_cacheable = 0;
-val->not_found = 0;
 
 gvvn = ngx_palloc(ctx->temp_pool,
   sizeof(ngx_stream_geo_variable_value_node_t));
___
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel