#2499 closed defect (invalid)

ngx_array_init/ngx_palloc strange behavior on zero size

Reported by: gertitomir@… Owned by:
Priority: minor Milestone:
Component: documentation Version: 1.19.x
Keywords: pool, ngx_palloc, ngx_array_init Cc:
uname -a: Linux andersen-pc 5.10.0-22-amd64 #1 SMP Debian 5.10.178-3 (2023-04-22) x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.22.1
built by gcc 10.2.1 20210110 (Debian 10.2.1-6)
configure arguments: --add-dynamic-module=/home/*****-module --prefix=/home/******-module/test/debug --conf-path=/home/andersen/work/nginx-swaf-module/test/test.conf --error-log-path=/dev/stdout --with-debug --with-cc-opt='-O0 -g'


ngx_array_init populates a valid elts pointer when n is zero. If you initialize several different arrays and specify the parameter n = 0, then all elts arrays will contain the same address. This is because inside ngx_array_init the ngx_palloc function returns a valid pointer when the allocation size is zero. It seems to me that this is incorrect behavior.

So first, there is a problem with ngx_palloc. Secondly, we need to add a check for the n parameter in the ngx_array_init function so that it considers n = 1 even if it is zero.

Change History (2)

comment:1 by Maxim Dounin, 14 months ago

It seems to me that this is incorrect behavior.

What makes you think so? It is an error to initialize an array with n = 0, and more or less any behaviour following such an error would be correct.

comment:2 by Maxim Dounin, 14 months ago

Resolution: invalid
Status: newclosed

Feedback timeout.

Note: See TracTickets for help on using tickets.