Welcome! Log In Create A New Profile

Advanced

Found a bug in ngx_http_complex_value

Posted by edo888 
Found a bug in ngx_http_complex_value
January 02, 2012 08:52PM
Hi,

I think I have found a bug in ngx_http_complex_value. Here is a piece from my code.

ngx_str_t first_tmp;
if (ngx_http_complex_value(r, &conf->first_value, &first_tmp) != NGX_OK) {
return NGX_ERROR;
}

ngx_str_t second_tmp;
if (ngx_http_complex_value(r, &conf->second_value, &second_tmp) != NGX_OK) {
return NGX_ERROR;
}

I'm debugging it with gdb and I have break points between the 2 ngx_http_complex_value calls

after the 1st call I have a break point and (gdb) print first_tmp:

{len = 2, data = 0x80126aa00 "aa"}

after the break point it calls the 2nd function and stops after it and (gdb) print first_tmp:

{len = 2, data = 0x80126aa00 "aabbbbbbbbb"}

then (gdb) print second_tmp:

{len = 9, data = 0x80126aa02 "bbbbbbbbb"}

When I'm logging the values for first_tmp and second_tmp in the nginx debug log with:
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "first_tmp: \"%V\"", &first_tmp);
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "second_tmp: \"%V\"", &second_tmp);

I'm getting a correct result which is:
first_tmp: "aa"
second_tmp: "bbbbbbbbb"

but in the code I'm getting different values for the 2 variables and the behaviour is not always the same.

So I have presumed that the len is correct which I can use to get what I want. Here I'm using a new variables first and second to remove the unnecessary parts from the tmp vars and to not hack the nginx core:

This goes right after the code above:

// fixing bug with ngx_http_complex_value
ngx_str_t first, second;
first.len = first_tmp.len;
second.len = second_tmp.len;
first.data = calloc(first_tmp.len, sizeof(char));
second.data = calloc(second_tmp.len, sizeof(char));
strncpy(first.data, first_tmp.data, first_tmp.len);
strncpy(second.data, second_tmp.data, second_tmp.len);

But I think that this should be fixed in the core.

I'm using nginx/1.0.10 from FreeBSD ports

Regards



Edited 1 time(s). Last edit at 01/02/2012 08:52PM by edo888.
Re: Found a bug in ngx_http_complex_value
January 02, 2012 09:09PM
BTW. Just noticed the addresses:

0x80126aa00
0x80126aa02

and I think that this is related to '\0' character.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 282
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