Welcome! Log In Create A New Profile

Advanced

filename resolution error after regex captures & matching if

Posted by dweeves 
filename resolution error after regex captures & matching if
November 29, 2012 10:01AM
First , i will apologize for the setup i use : cygwin recompilation of nginx 1.2.5 source (not very officially supported) , but i noticed this :
(using --with-debug compilation)

I think i found a bug in the filename construction from regexp (when using a matching if before)


Problematic configuration entry:

location ~ ^/test1/hls/(.*?/*)\.m3u(.)
{
alias //gagarine/poubelle/seb/hls/$1.m3u$2;
if ($hlsexp)
{
expires 0;
}
}

I'll put a "Analyzed debug log" alongside the corresponding config part i suppose it matches



-- DEBUG LOG EXTRACT --

-- HERE IS THE REQUEST --
2012/11/29 15:16:18 [debug] 2044#0: *2 http request line: "GET /test1/hls/titi/index-timeshifting.m3u8 HTTP/1.1"
2012/11/29 15:16:18 [debug] 2044#0: *2 http uri: "/test1/hls/titi/index-timeshifting.m3u8"
2012/11/29 15:16:18 [debug] 2044#0: *2 http args: ""
2012/11/29 15:16:18 [debug] 2044#0: *2 http exten: "m3u8"
2012/11/29 15:16:18 [debug] 2044#0: *2 http process request header line
2012/11/29 15:16:18 [debug] 2044#0: *2 http header: "Host: 172.18.200.233"
2012/11/29 15:16:18 [debug] 2044#0: *2 http header: "Connection: keep-alive"
2012/11/29 15:16:18 [debug] 2044#0: *2 http header: "Cache-Control: max-age=0"
2012/11/29 15:16:18 [debug] 2044#0: *2 http header: "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.91 Safari/537.11"
2012/11/29 15:16:18 [debug] 2044#0: *2 http header: "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
2012/11/29 15:16:18 [debug] 2044#0: *2 http header: "Accept-Encoding: gzip,deflate,sdch"
2012/11/29 15:16:18 [debug] 2044#0: *2 http header: "Accept-Language: fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4"
2012/11/29 15:16:18 [debug] 2044#0: *2 http header: "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3"
2012/11/29 15:16:18 [debug] 2044#0: *2 http header: "Cookie: consoleSessionId=gkzdbGM7T2XpOmVL"
2012/11/29 15:16:18 [debug] 2044#0: *2 http header done
-- REQUEST IDENTIFICATION END --

2012/11/29 15:16:18 [debug] 2044#0: *2 event timer del: 7: 1283940725
2012/11/29 15:16:18 [debug] 2044#0: *2 rewrite phase: 0

-- VALUE SETTINGS LOG --
2012/11/29 15:16:18 [debug] 2044#0: *2 http script value: "1"
2012/11/29 15:16:18 [debug] 2044#0: *2 http script set $hlsexp
2012/11/29 15:16:18 [debug] 2044#0: *2 http script value: "0"
2012/11/29 15:16:18 [debug] 2044#0: *2 http script set $ssexp
-- ASSOCIATED CONF ENTRY --
set $hlsexp "1";
set $ssexp "0";




-- LOCATION MATCHING --
2012/11/29 15:16:18 [debug] 2044#0: *2 test location: "^/test1/hls/"
2012/11/29 15:16:18 [debug] 2044#0: *2 test location: "/"
2012/11/29 15:16:18 [debug] 2044#0: *2 test location: "crossdomain.xml"
2012/11/29 15:16:18 [debug] 2044#0: *2 test location: "hls/"
2012/11/29 15:16:18 [debug] 2044#0: *2 test location: ~ "^/ss/(.*).isml?/Manifest(.*)$"
2012/11/29 15:16:18 [debug] 2044#0: *2 test location: ~ "/ss/(.*)/Manifest(.*)$"
2012/11/29 15:16:18 [debug] 2044#0: *2 test location: ~ "^/ss/(.*)\.isml?/QualityLevels.*$"
2012/11/29 15:16:18 [debug] 2044#0: *2 test location: ~ "^/ss/.*/.*/QL_.*$"
2012/11/29 15:16:18 [debug] 2044#0: *2 test location: ~ "^/test1/hls/(.*?/*)\.m3u(.)"
2012/11/29 15:16:18 [debug] 2044#0: *2 using configuration "^/test1/hls/(.*?/*)\.m3u(.)"
-- IT FINDS THE GOOD ENTRY ACCORDING FOLLOWING CONF --
location ~ ^/test1/hls/(.*?/*)\.m3u(.)

-- REWRITING PHASE --
2012/11/29 15:16:18 [debug] 2044#0: *2 http cl:-1 max:1048576
2012/11/29 15:16:18 [debug] 2044#0: *2 rewrite phase: 2
2012/11/29 15:16:18 [debug] 2044#0: *2 http script var
2012/11/29 15:16:18 [debug] 2044#0: *2 http script var: "1"
2012/11/29 15:16:18 [debug] 2044#0: *2 http script if
2012/11/29 15:16:18 [debug] 2044#0: *2 post rewrite phase: 3
2012/11/29 15:16:18 [debug] 2044#0: *2 generic phase: 4
2012/11/29 15:16:18 [debug] 2044#0: *2 generic phase: 5
2012/11/29 15:16:18 [debug] 2044#0: *2 access phase: 6
2012/11/29 15:16:18 [debug] 2044#0: *2 access phase: 7
2012/11/29 15:16:18 [debug] 2044#0: *2 post access phase: 8
2012/11/29 15:16:18 [debug] 2044#0: *2 content phase: 9
2012/11/29 15:16:18 [debug] 2044#0: *2 content phase: 10
2012/11/29 15:16:18 [debug] 2044#0: *2 content phase: 11
-- THIS SEEMS ALMOST NORMAL --
2012/11/29 15:16:18 [debug] 2044#0: *2 http script copy: "//gagarine/poubelle/seb/hls/"
2012/11/29 15:16:18 [debug] 2044#0: *2 http script capture: "titi/index-timeshifting"
2012/11/29 15:16:18 [debug] 2044#0: *2 http script copy: ".m3u"
2012/11/29 15:16:18 [debug] 2044#0: *2 http script capture: "8"
-- CAPTURE GROUPS SEEM TO BE OK ACCORDING TO :
location ~ ^/test1/hls/(.*?/*)\.m3u(.)
and
alias //gagarine/poubelle/seb/hls/$1.m3u$2;

-- THE BUG IS HERE --
2012/11/29 15:16:18 [debug] 2044#0: *2 http filename: "//gagarine/poubelle/seb/hls/titi/index-timeshifting.m3u8hifting.m3u8"

it seems that some internal buffer is not set to the good length.
there is an extra "hifting.m3u8" at the end that should not be there.


INTERESTING NOTE:
-------------------------------

if the $hlsexp is set to "0" then the bug does not appear , the final "filename" variable has the good length.


Any help will be appreciated



Edited 1 time(s). Last edit at 11/29/2012 10:03AM by dweeves.
Re: filename resolution error after regex captures & matching if
November 30, 2012 08:47AM
after investigation, it seems that something goes wrong in:
- ngx_http_map_uri_to_path function of src/http/ngx_http_core_module.c file

This line:

last = ngx_cpystrn(last, r->uri.data + alias, r->uri.len - alias + 1);

is adding the extra unwanted chars to last.

I cannot figure out why it did not enter the following code that would have skipped this extra string manipulation:

#if (NGX_PCRE)
if (captures) {
if (!r->add_uri_to_alias) {
*last = '\0';
return last;
}

alias = 0;
}
#endif

it seems that r->add_uri_to_alias is set to true for whatever reason , preventing to enter in the return last block & calling the unwanted (in my case) strncpy .
Sorry, only registered users may post in this forum.

Click here to login

Online Users

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