From: Greg Beaver Date: Mon, 5 Feb 2007 07:19:35 +0000 (+0000) Subject: improve error message empty entry => empty directory. Add check for phar://blah... X-Git-Tag: RELEASE_1_0_0RC1~16 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c0e2739103786e4034c858219eb67b7eb095457b;p=php improve error message empty entry => empty directory. Add check for phar://blah.phar/. and phar://blah.phar/.. --- diff --git a/ext/phar/phar_path_check.c b/ext/phar/phar_path_check.c index 50c3a46e05..d2d81a3770 100755 --- a/ext/phar/phar_path_check.c +++ b/ext/phar/phar_path_check.c @@ -1,4 +1,4 @@ -/* Generated by re2c 0.11.0 on Sun Feb 4 14:40:54 2007 */ +/* Generated by re2c 0.11.0 on Mon Feb 5 01:18:16 2007 */ #line 1 "ext/phar/phar_path_check.re" /* +----------------------------------------------------------------------+ @@ -26,6 +26,13 @@ phar_path_check_result phar_path_check(char **s, int *len, const char **error) { const unsigned char *p = (const unsigned char*)*s; const unsigned char *m; + if (*len == 1 && *p == '.') { + *error = "current directory reference"; + return pcr_err_curr_dir; + } else if (*len == 2 && p[0] == '.' && p[1] == '.') { + *error = "upper directory reference"; + return pcr_err_up_dir; + } #define YYCTYPE unsigned char #define YYCURSOR p #define YYLIMIT p+*len @@ -35,7 +42,7 @@ phar_path_check_result phar_path_check(char **s, int *len, const char **error) loop: { -#line 39 "ext/phar/phar_path_check.c" +#line 46 "ext/phar/phar_path_check.c" { YYCTYPE yych; @@ -69,30 +76,30 @@ yy3: if(yych <= '.') goto yy16; if(yych <= '/') goto yy17; yy4: -#line 78 "ext/phar/phar_path_check.re" +#line 85 "ext/phar/phar_path_check.re" { goto loop; } -#line 77 "ext/phar/phar_path_check.c" +#line 84 "ext/phar/phar_path_check.c" yy5: ++YYCURSOR; -#line 50 "ext/phar/phar_path_check.re" +#line 57 "ext/phar/phar_path_check.re" { *error = "back-slash"; return pcr_err_back_slash; } -#line 85 "ext/phar/phar_path_check.c" +#line 92 "ext/phar/phar_path_check.c" yy7: ++YYCURSOR; -#line 58 "ext/phar/phar_path_check.re" +#line 65 "ext/phar/phar_path_check.re" { *error = "star"; return pcr_err_star; } -#line 93 "ext/phar/phar_path_check.c" +#line 100 "ext/phar/phar_path_check.c" yy9: ++YYCURSOR; -#line 62 "ext/phar/phar_path_check.re" +#line 69 "ext/phar/phar_path_check.re" { if (**s == '/') { (*s)++; @@ -101,10 +108,10 @@ yy9: *error = NULL; return pcr_use_query; } -#line 105 "ext/phar/phar_path_check.c" +#line 112 "ext/phar/phar_path_check.c" yy11: ++YYCURSOR; -#line 70 "ext/phar/phar_path_check.re" +#line 77 "ext/phar/phar_path_check.re" { if (**s == '/') { (*s)++; @@ -113,18 +120,18 @@ yy11: *error = NULL; return pcr_is_ok; } -#line 117 "ext/phar/phar_path_check.c" +#line 124 "ext/phar/phar_path_check.c" yy13: yych = *++YYCURSOR; goto yy4; yy14: ++YYCURSOR; -#line 54 "ext/phar/phar_path_check.re" +#line 61 "ext/phar/phar_path_check.re" { - *error = "empty entry"; + *error = "empty directory"; return pcr_err_empty_entry; } -#line 128 "ext/phar/phar_path_check.c" +#line 135 "ext/phar/phar_path_check.c" yy16: yych = *++YYCURSOR; if(yych <= 0x00) goto yy20; @@ -134,12 +141,12 @@ yy16: goto yy2; yy17: ++YYCURSOR; -#line 38 "ext/phar/phar_path_check.re" +#line 45 "ext/phar/phar_path_check.re" { *error = "double slash"; return pcr_err_double_slash; } -#line 143 "ext/phar/phar_path_check.c" +#line 150 "ext/phar/phar_path_check.c" yy19: yych = *++YYCURSOR; if(yych <= 0x00) goto yy22; @@ -147,22 +154,22 @@ yy19: goto yy2; yy20: ++YYCURSOR; -#line 46 "ext/phar/phar_path_check.re" +#line 53 "ext/phar/phar_path_check.re" { *error = "current directory reference"; return pcr_err_curr_dir; } -#line 156 "ext/phar/phar_path_check.c" +#line 163 "ext/phar/phar_path_check.c" yy22: ++YYCURSOR; -#line 42 "ext/phar/phar_path_check.re" +#line 49 "ext/phar/phar_path_check.re" { *error = "upper directory reference"; return pcr_err_up_dir; } -#line 164 "ext/phar/phar_path_check.c" +#line 171 "ext/phar/phar_path_check.c" } } -#line 81 "ext/phar/phar_path_check.re" +#line 88 "ext/phar/phar_path_check.re" } diff --git a/ext/phar/phar_path_check.re b/ext/phar/phar_path_check.re index 1caac5c108..07b113ddb6 100755 --- a/ext/phar/phar_path_check.re +++ b/ext/phar/phar_path_check.re @@ -24,6 +24,13 @@ phar_path_check_result phar_path_check(char **s, int *len, const char **error) { const unsigned char *p = (const unsigned char*)*s; const unsigned char *m; + if (*len == 1 && *p == '.') { + *error = "current directory reference"; + return pcr_err_curr_dir; + } else if (*len == 2 && p[0] == '.' && p[1] == '.') { + *error = "upper directory reference"; + return pcr_err_up_dir; + } #define YYCTYPE unsigned char #define YYCURSOR p #define YYLIMIT p+*len @@ -52,7 +59,7 @@ ANY = .; return pcr_err_back_slash; } "/" END { - *error = "empty entry"; + *error = "empty directory"; return pcr_err_empty_entry; } "*" { diff --git a/ext/phar/tests/create_path_error.phpt b/ext/phar/tests/create_path_error.phpt index f19df183d6..16176b6ad7 100755 --- a/ext/phar/tests/create_path_error.phpt +++ b/ext/phar/tests/create_path_error.phpt @@ -27,10 +27,10 @@ function error_handler($errno, $errmsg) set_error_handler('error_handler'); -$checks = array('//', '/.', '/../', '/a/..'); +$checks = array('/', '.', '../', 'a/..', 'a/', 'b//a.php'); foreach($checks as $check) { - file_put_contents($pname . $check, "error"); + file_put_contents($pname . '/' . $check, "error"); } ?> @@ -40,7 +40,10 @@ foreach($checks as $check) --EXPECTF-- string(5) "query" string(5) "query" -Error: file_put_contents(phar://%s//): failed to open stream: phar error: invalid path "/" contains empty entry -Error: file_put_contents(phar://%s/../): failed to open stream: phar error: invalid path "../" contains empty entry +Error: file_put_contents(phar://%s//): failed to open stream: phar error: invalid path "/" contains empty directory +Error: file_put_contents(phar://%s/.): failed to open stream: phar error: invalid path "." contains current directory reference +Error: file_put_contents(phar://%s/../): failed to open stream: phar error: invalid path "../" contains empty directory Error: file_put_contents(phar://%s/a/..): failed to open stream: phar error: invalid path "a/.." contains upper directory reference +Error: file_put_contents(phar://%s/a/): failed to open stream: phar error: invalid path "a/" contains empty directory +Error: file_put_contents(phar://%s/b//a.php): failed to open stream: phar error: invalid path "b//a.php" contains double slash ===DONE=== diff --git a/ext/phar/tests/phar_offset_get_error.phpt b/ext/phar/tests/phar_offset_get_error.phpt index 75d5e0af0b..e89b98570a 100755 --- a/ext/phar/tests/phar_offset_get_error.phpt +++ b/ext/phar/tests/phar_offset_get_error.phpt @@ -32,6 +32,6 @@ include($pname . $iname); --CLEAN-- --EXPECT-- -Entry /error/ does not exist and cannot be created: phar error: invalid path "/error/" contains empty entry +Entry /error/ does not exist and cannot be created: phar error: invalid path "/error/" contains empty directory foobar ===DONE===