Maxim Dounin
August 17, 2021 06:44PM
Hello!

On Tue, Aug 17, 2021 at 03:28:10PM +0000, Eran Kornblau wrote:

> 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;

Yes, that's known inconsistency. Unfortunately, there is no easy
fix. Current approach is to use null-terminated string ignoring
len if zero is used (see e48ac0136ee3, 9a970c905045) until someone
will came up with a good fix.

--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

Inconsistent len of complex value using zero flag

erankor 514 August 17, 2021 11:30AM

Re: Inconsistent len of complex value using zero flag

Maxim Dounin 230 August 17, 2021 06:44PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 259
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready