xref: /PHP-7.1/ext/phar/phar_path_check.c (revision 4ee90985)
1 /* Generated by re2c 0.16 */
2 #line 1 "ext/phar/phar_path_check.re"
3 /*
4   +----------------------------------------------------------------------+
5   | phar php single-file executable PHP extension                        |
6   +----------------------------------------------------------------------+
7   | Copyright (c) 2007-2018 The PHP Group                                |
8   +----------------------------------------------------------------------+
9   | This source file is subject to version 3.01 of the PHP license,      |
10   | that is bundled with this package in the file LICENSE, and is        |
11   | available through the world-wide-web at the following url:           |
12   | http://www.php.net/license/3_01.txt.                                 |
13   | If you did not receive a copy of the PHP license and are unable to   |
14   | obtain it through the world-wide-web, please send a note to          |
15   | license@php.net so we can mail you a copy immediately.               |
16   +----------------------------------------------------------------------+
17   | Authors: Marcus Boerger <helly@php.net>                              |
18   +----------------------------------------------------------------------+
19 */
20 
21 /* $Id$ */
22 
23 #include "phar_internal.h"
24 
phar_path_check(char ** s,int * len,const char ** error)25 phar_path_check_result phar_path_check(char **s, int *len, const char **error)
26 {
27 	const unsigned char *p = (const unsigned char*)*s;
28 	const unsigned char *m;
29 
30 	if (*len == 1 && *p == '.') {
31 		*error = "current directory reference";
32 		return pcr_err_curr_dir;
33 	} else if (*len == 2 && p[0] == '.' && p[1] == '.') {
34 		*error = "upper directory reference";
35 		return pcr_err_up_dir;
36 	}
37 
38 #define YYCTYPE         unsigned char
39 #define YYCURSOR        p
40 #define YYLIMIT         p+*len
41 #define YYMARKER        m
42 #define YYFILL(n)
43 
44 loop:
45 
46 #line 47 "ext/phar/phar_path_check.c"
47 {
48 	YYCTYPE yych;
49 	unsigned int yyaccept = 0;
50 	if ((YYLIMIT - YYCURSOR) < 4) YYFILL(4);
51 	yych = *YYCURSOR;
52 	if (yych <= '[') {
53 		if (yych <= ')') {
54 			if (yych <= '\f') {
55 				if (yych >= 0x01) goto yy4;
56 			} else {
57 				if (yych <= '\r') goto yy6;
58 				if (yych <= 0x19) goto yy4;
59 				goto yy7;
60 			}
61 		} else {
62 			if (yych <= '/') {
63 				if (yych <= '*') goto yy9;
64 				if (yych <= '.') goto yy7;
65 				goto yy11;
66 			} else {
67 				if (yych == '?') goto yy12;
68 				goto yy7;
69 			}
70 		}
71 	} else {
72 		if (yych <= 0xEC) {
73 			if (yych <= 0xC1) {
74 				if (yych <= '\\') goto yy14;
75 				if (yych <= 0x7F) goto yy7;
76 				goto yy4;
77 			} else {
78 				if (yych <= 0xDF) goto yy16;
79 				if (yych <= 0xE0) goto yy17;
80 				goto yy18;
81 			}
82 		} else {
83 			if (yych <= 0xF0) {
84 				if (yych <= 0xED) goto yy19;
85 				if (yych <= 0xEF) goto yy18;
86 				goto yy20;
87 			} else {
88 				if (yych <= 0xF3) goto yy21;
89 				if (yych <= 0xF4) goto yy22;
90 				goto yy4;
91 			}
92 		}
93 	}
94 	++YYCURSOR;
95 #line 93 "ext/phar/phar_path_check.re"
96 	{
97 			if (**s == '/') {
98 				(*s)++;
99 				(*len)--;
100 			}
101 			if ((p - (const unsigned char*)*s) - 1 != *len)
102 			{
103 				*error ="illegal character";
104 				return pcr_err_illegal_char;
105 			}
106 			*error = NULL;
107 			return pcr_is_ok;
108 		}
109 #line 110 "ext/phar/phar_path_check.c"
110 yy4:
111 	++YYCURSOR;
112 yy5:
113 #line 106 "ext/phar/phar_path_check.re"
114 	{
115 			*error ="illegal character";
116 			return pcr_err_illegal_char;
117 		}
118 #line 119 "ext/phar/phar_path_check.c"
119 yy6:
120 	yych = *++YYCURSOR;
121 	if (yych == '\n') goto yy4;
122 	goto yy5;
123 yy7:
124 	++YYCURSOR;
125 yy8:
126 #line 90 "ext/phar/phar_path_check.re"
127 	{
128 			goto loop;
129 		}
130 #line 131 "ext/phar/phar_path_check.c"
131 yy9:
132 	++YYCURSOR;
133 #line 78 "ext/phar/phar_path_check.re"
134 	{
135 			*error = "star";
136 			return pcr_err_star;
137 		}
138 #line 139 "ext/phar/phar_path_check.c"
139 yy11:
140 	yyaccept = 0;
141 	yych = *(YYMARKER = ++YYCURSOR);
142 	if (yych <= '-') goto yy8;
143 	if (yych <= '.') goto yy23;
144 	if (yych <= '/') goto yy25;
145 	goto yy8;
146 yy12:
147 	++YYCURSOR;
148 #line 82 "ext/phar/phar_path_check.re"
149 	{
150 			if (**s == '/') {
151 				(*s)++;
152 			}
153 			*len = (p - (const unsigned char*)*s) -1;
154 			*error = NULL;
155 			return pcr_use_query;
156 		}
157 #line 158 "ext/phar/phar_path_check.c"
158 yy14:
159 	++YYCURSOR;
160 #line 74 "ext/phar/phar_path_check.re"
161 	{
162 			*error = "back-slash";
163 			return pcr_err_back_slash;
164 		}
165 #line 166 "ext/phar/phar_path_check.c"
166 yy16:
167 	yych = *++YYCURSOR;
168 	if (yych <= 0x7F) goto yy5;
169 	if (yych <= 0xBF) goto yy7;
170 	goto yy5;
171 yy17:
172 	yyaccept = 1;
173 	yych = *(YYMARKER = ++YYCURSOR);
174 	if (yych <= 0x9F) goto yy5;
175 	if (yych <= 0xBF) goto yy27;
176 	goto yy5;
177 yy18:
178 	yyaccept = 1;
179 	yych = *(YYMARKER = ++YYCURSOR);
180 	if (yych <= 0x7F) goto yy5;
181 	if (yych <= 0xBF) goto yy27;
182 	goto yy5;
183 yy19:
184 	yyaccept = 1;
185 	yych = *(YYMARKER = ++YYCURSOR);
186 	if (yych <= 0x7F) goto yy5;
187 	if (yych <= 0x9F) goto yy27;
188 	goto yy5;
189 yy20:
190 	yyaccept = 1;
191 	yych = *(YYMARKER = ++YYCURSOR);
192 	if (yych <= 0x8F) goto yy5;
193 	if (yych <= 0xBF) goto yy28;
194 	goto yy5;
195 yy21:
196 	yyaccept = 1;
197 	yych = *(YYMARKER = ++YYCURSOR);
198 	if (yych <= 0x7F) goto yy5;
199 	if (yych <= 0xBF) goto yy28;
200 	goto yy5;
201 yy22:
202 	yyaccept = 1;
203 	yych = *(YYMARKER = ++YYCURSOR);
204 	if (yych <= 0x7F) goto yy5;
205 	if (yych <= 0x8F) goto yy28;
206 	goto yy5;
207 yy23:
208 	yych = *++YYCURSOR;
209 	if (yych <= 0x00) goto yy29;
210 	if (yych <= '-') goto yy24;
211 	if (yych <= '.') goto yy31;
212 	if (yych <= '/') goto yy29;
213 yy24:
214 	YYCURSOR = YYMARKER;
215 	if (yyaccept == 0) {
216 		goto yy8;
217 	} else {
218 		goto yy5;
219 	}
220 yy25:
221 	++YYCURSOR;
222 #line 62 "ext/phar/phar_path_check.re"
223 	{
224 			*error = "double slash";
225 			return pcr_err_double_slash;
226 		}
227 #line 228 "ext/phar/phar_path_check.c"
228 yy27:
229 	yych = *++YYCURSOR;
230 	if (yych <= 0x7F) goto yy24;
231 	if (yych <= 0xBF) goto yy7;
232 	goto yy24;
233 yy28:
234 	yych = *++YYCURSOR;
235 	if (yych <= 0x7F) goto yy24;
236 	if (yych <= 0xBF) goto yy27;
237 	goto yy24;
238 yy29:
239 	++YYCURSOR;
240 #line 70 "ext/phar/phar_path_check.re"
241 	{
242 			*error = "current directory reference";
243 			return pcr_err_curr_dir;
244 		}
245 #line 246 "ext/phar/phar_path_check.c"
246 yy31:
247 	yych = *++YYCURSOR;
248 	if (yych <= 0x00) goto yy32;
249 	if (yych != '/') goto yy24;
250 yy32:
251 	++YYCURSOR;
252 #line 66 "ext/phar/phar_path_check.re"
253 	{
254 			*error = "upper directory reference";
255 			return pcr_err_up_dir;
256 		}
257 #line 258 "ext/phar/phar_path_check.c"
258 }
259 #line 110 "ext/phar/phar_path_check.re"
260 
261 }
262