Inconsistent len of complex value using zero flag

Eran Kornblau eran.kornblau at kaltura.com
Tue Aug 17 15:28:10 UTC 2021


Hi all,

Something I bumped into today –

When using the zero flag of ngx_http_compile_complex_value_t (for example, using
ngx_http_set_complex_value_zero_slot) the length of the resulting string is inconsistent -

  1.  If the complex value is a simple string, the length does not include the null terminator.
  2.  If the complex value includes variables, the length includes the null terminator.

This happens because ngx_http_script_done adds code to copy the null explicitly, while simple strings
are copied as-is from val->value at the beginning of ngx_http_complex_value.

I assume that usually the length is not used when asking for a null terminated string.
However, in my case, I’m parsing the resulting value, and I’m supporting several different formats.
In some flows, I’m parsing the value using nginx functions (e.g. ngx_atoi) while in other flows,
I’m using a glibc function (strptime).

IMHO, the correct behavior is to change the impl so that it will never count the null terminator in the length.
Maybe add a ‘zero’ flag on ngx_http_complex_value_t, and do something like –
value->len = len – val->zero;

Thanks

Eran

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20210817/97452eee/attachment.htm>


More information about the nginx-devel mailing list