]> granicus.if.org Git - php/commitdiff
improve error message empty entry => empty directory. Add check for phar://blah...
authorGreg Beaver <cellog@php.net>
Mon, 5 Feb 2007 07:19:35 +0000 (07:19 +0000)
committerGreg Beaver <cellog@php.net>
Mon, 5 Feb 2007 07:19:35 +0000 (07:19 +0000)
ext/phar/phar_path_check.c
ext/phar/phar_path_check.re
ext/phar/tests/create_path_error.phpt
ext/phar/tests/phar_offset_get_error.phpt

index 50c3a46e05afb1e00a9fb30ae6bc42e2742185d8..d2d81a3770de68389db6782969c3e148374a3c17 100755 (executable)
@@ -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"
 
 }
index 1caac5c108d2eac2781c05d8c5f940f727e8635d..07b113ddb614a0987b63c4ae03f714e136154497 100755 (executable)
@@ -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;
                }
 "*" {
index f19df183d64d7a46146ac0e5415cb8953117ee08..16176b6ad73ff7c5c47a7b1927f91c2ce414d302 100755 (executable)
@@ -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===
index 75d5e0af0bb991ce7f12f72ba790c195eb6cfcea..e89b98570a5a62c2dfae560677727a7a4ce0c7e4 100755 (executable)
@@ -32,6 +32,6 @@ include($pname . $iname);
 --CLEAN--
 <?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
 --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===