Inconsistent len of complex value using zero flag

Maxim Dounin mdounin at mdounin.ru
Tue Aug 17 22:43:07 UTC 2021


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/


More information about the nginx-devel mailing list