Line | Source Code | Coverage |
---|
1 | /************************************************* | - |
2 | * Perl-Compatible Regular Expressions * | - |
3 | *************************************************/ | - |
4 | | - |
5 | /* PCRE is a library of functions to support regular expressions whose syntax | - |
6 | and semantics are as close as possible to those of the Perl 5 language. | - |
7 | | - |
8 | Written by Philip Hazel | - |
9 | Copyright (c) 1997-2012 University of Cambridge | - |
10 | | - |
11 | ----------------------------------------------------------------------------- | - |
12 | Redistribution and use in source and binary forms, with or without | - |
13 | modification, are permitted provided that the following conditions are met: | - |
14 | | - |
15 | * Redistributions of source code must retain the above copyright notice, | - |
16 | this list of conditions and the following disclaimer. | - |
17 | | - |
18 | * Redistributions in binary form must reproduce the above copyright | - |
19 | notice, this list of conditions and the following disclaimer in the | - |
20 | documentation and/or other materials provided with the distribution. | - |
21 | | - |
22 | * Neither the name of the University of Cambridge nor the names of its | - |
23 | contributors may be used to endorse or promote products derived from | - |
24 | this software without specific prior written permission. | - |
25 | | - |
26 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | - |
27 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | - |
28 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | - |
29 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | - |
30 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | - |
31 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | - |
32 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | - |
33 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | - |
34 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | - |
35 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | - |
36 | POSSIBILITY OF SUCH DAMAGE. | - |
37 | ----------------------------------------------------------------------------- | - |
38 | */ | - |
39 | | - |
40 | | - |
41 | /* This module contains an internal function that tests a compiled pattern to | - |
42 | see if it was compiled with the opposite endianness. If so, it uses an | - |
43 | auxiliary local function to flip the appropriate bytes. */ | - |
44 | | - |
45 | | - |
46 | #ifdef PCRE_HAVE_CONFIG_H | - |
47 | #include "config.h" | - |
48 | #endif | - |
49 | | - |
50 | #include "pcre_internal.h" | - |
51 | | - |
52 | | - |
53 | /************************************************* | - |
54 | * Swap byte functions * | - |
55 | *************************************************/ | - |
56 | | - |
57 | /* The following functions swap the bytes of a pcre_uint16 | - |
58 | and pcre_uint32 value. | - |
59 | | - |
60 | Arguments: | - |
61 | value any number | - |
62 | | - |
63 | Returns: the byte swapped value | - |
64 | */ | - |
65 | | - |
66 | static pcre_uint32 | - |
67 | swap_uint32(pcre_uint32 value) | - |
68 | { | - |
69 | return ((value & 0x000000ff) << 24) | never executed: return ((value & 0x000000ff) << 24) | ((value & 0x0000ff00) << 8) | ((value & 0x00ff0000) >> 8) | (value >> 24); | 0 |
70 | ((value & 0x0000ff00) << 8) | never executed: return ((value & 0x000000ff) << 24) | ((value & 0x0000ff00) << 8) | ((value & 0x00ff0000) >> 8) | (value >> 24); | 0 |
71 | ((value & 0x00ff0000) >> 8) | never executed: return ((value & 0x000000ff) << 24) | ((value & 0x0000ff00) << 8) | ((value & 0x00ff0000) >> 8) | (value >> 24); | 0 |
72 | (value >> 24); never executed: return ((value & 0x000000ff) << 24) | ((value & 0x0000ff00) << 8) | ((value & 0x00ff0000) >> 8) | (value >> 24); | 0 |
73 | } | - |
74 | | - |
75 | static pcre_uint16 | - |
76 | swap_uint16(pcre_uint16 value) | - |
77 | { | - |
78 | return (value >> 8) | (value << 8); never executed: return (value >> 8) | (value << 8); | 0 |
79 | } | - |
80 | | - |
81 | | - |
82 | /************************************************* | - |
83 | * Test for a byte-flipped compiled regex * | - |
84 | *************************************************/ | - |
85 | | - |
86 | /* This function swaps the bytes of a compiled pattern usually | - |
87 | loaded form the disk. It also sets the tables pointer, which | - |
88 | is likely an invalid pointer after reload. | - |
89 | | - |
90 | Arguments: | - |
91 | argument_re points to the compiled expression | - |
92 | extra_data points to extra data or is NULL | - |
93 | tables points to the character tables or NULL | - |
94 | | - |
95 | Returns: 0 if the swap is successful, negative on error | - |
96 | */ | - |
97 | | - |
98 | #ifdef COMPILE_PCRE8 | - |
99 | PCRE_EXP_DECL int pcre_pattern_to_host_byte_order(pcre *argument_re, | - |
100 | pcre_extra *extra_data, const unsigned char *tables) | - |
101 | #else | - |
102 | PCRE_EXP_DECL int pcre16_pattern_to_host_byte_order(pcre16 *argument_re, | - |
103 | pcre16_extra *extra_data, const unsigned char *tables) | - |
104 | #endif | - |
105 | { | - |
106 | REAL_PCRE *re = (REAL_PCRE *)argument_re; never executed (the execution status of this line is deduced): real_pcre16 *re = (real_pcre16 *)argument_re; | - |
107 | pcre_study_data *study; never executed (the execution status of this line is deduced): pcre_study_data *study; | - |
108 | #ifndef COMPILE_PCRE8 | - |
109 | pcre_uchar *ptr; never executed (the execution status of this line is deduced): pcre_uchar *ptr; | - |
110 | int length; never executed (the execution status of this line is deduced): int length; | - |
111 | #ifdef SUPPORT_UTF | - |
112 | BOOL utf; never executed (the execution status of this line is deduced): BOOL utf; | - |
113 | BOOL utf16_char; never executed (the execution status of this line is deduced): BOOL utf16_char; | - |
114 | #endif /* SUPPORT_UTF */ | - |
115 | #endif /* !COMPILE_PCRE8 */ | - |
116 | | - |
117 | if (re == NULL) return PCRE_ERROR_NULL; never executed: return (-2); never evaluated: re == ((void *)0) | 0 |
118 | if (re->magic_number == MAGIC_NUMBER) never evaluated: re->magic_number == 0x50435245UL | 0 |
119 | { | - |
120 | if ((re->flags & PCRE_MODE) == 0) return PCRE_ERROR_BADMODE; never executed: return (-28); never evaluated: (re->flags & 0x0002) == 0 | 0 |
121 | re->tables = tables; never executed (the execution status of this line is deduced): re->tables = tables; | - |
122 | return 0; never executed: return 0; | 0 |
123 | } | - |
124 | | - |
125 | if (re->magic_number != REVERSED_MAGIC_NUMBER) return PCRE_ERROR_BADMAGIC; never executed: return (-4); never evaluated: re->magic_number != 0x45524350UL | 0 |
126 | if ((swap_uint16(re->flags) & PCRE_MODE) == 0) return PCRE_ERROR_BADMODE; never executed: return (-28); never evaluated: (swap_uint16(re->flags) & 0x0002) == 0 | 0 |
127 | | - |
128 | re->magic_number = MAGIC_NUMBER; never executed (the execution status of this line is deduced): re->magic_number = 0x50435245UL; | - |
129 | re->size = swap_uint32(re->size); never executed (the execution status of this line is deduced): re->size = swap_uint32(re->size); | - |
130 | re->options = swap_uint32(re->options); never executed (the execution status of this line is deduced): re->options = swap_uint32(re->options); | - |
131 | re->flags = swap_uint16(re->flags); never executed (the execution status of this line is deduced): re->flags = swap_uint16(re->flags); | - |
132 | re->top_bracket = swap_uint16(re->top_bracket); never executed (the execution status of this line is deduced): re->top_bracket = swap_uint16(re->top_bracket); | - |
133 | re->top_backref = swap_uint16(re->top_backref); never executed (the execution status of this line is deduced): re->top_backref = swap_uint16(re->top_backref); | - |
134 | re->first_char = swap_uint16(re->first_char); never executed (the execution status of this line is deduced): re->first_char = swap_uint16(re->first_char); | - |
135 | re->req_char = swap_uint16(re->req_char); never executed (the execution status of this line is deduced): re->req_char = swap_uint16(re->req_char); | - |
136 | re->name_table_offset = swap_uint16(re->name_table_offset); never executed (the execution status of this line is deduced): re->name_table_offset = swap_uint16(re->name_table_offset); | - |
137 | re->name_entry_size = swap_uint16(re->name_entry_size); never executed (the execution status of this line is deduced): re->name_entry_size = swap_uint16(re->name_entry_size); | - |
138 | re->name_count = swap_uint16(re->name_count); never executed (the execution status of this line is deduced): re->name_count = swap_uint16(re->name_count); | - |
139 | re->ref_count = swap_uint16(re->ref_count); never executed (the execution status of this line is deduced): re->ref_count = swap_uint16(re->ref_count); | - |
140 | re->tables = tables; never executed (the execution status of this line is deduced): re->tables = tables; | - |
141 | | - |
142 | if (extra_data != NULL && (extra_data->flags & PCRE_EXTRA_STUDY_DATA) != 0) never evaluated: extra_data != ((void *)0) never evaluated: (extra_data->flags & 0x0001) != 0 | 0 |
143 | { | - |
144 | study = (pcre_study_data *)extra_data->study_data; never executed (the execution status of this line is deduced): study = (pcre_study_data *)extra_data->study_data; | - |
145 | study->size = swap_uint32(study->size); never executed (the execution status of this line is deduced): study->size = swap_uint32(study->size); | - |
146 | study->flags = swap_uint32(study->flags); never executed (the execution status of this line is deduced): study->flags = swap_uint32(study->flags); | - |
147 | study->minlength = swap_uint32(study->minlength); never executed (the execution status of this line is deduced): study->minlength = swap_uint32(study->minlength); | - |
148 | } | 0 |
149 | | - |
150 | #ifndef COMPILE_PCRE8 | - |
151 | ptr = (pcre_uchar *)re + re->name_table_offset; never executed (the execution status of this line is deduced): ptr = (pcre_uchar *)re + re->name_table_offset; | - |
152 | length = re->name_count * re->name_entry_size; never executed (the execution status of this line is deduced): length = re->name_count * re->name_entry_size; | - |
153 | #ifdef SUPPORT_UTF | - |
154 | utf = (re->options & PCRE_UTF16) != 0; never executed (the execution status of this line is deduced): utf = (re->options & 0x00000800) != 0; | - |
155 | utf16_char = FALSE; never executed (the execution status of this line is deduced): utf16_char = 0; | - |
156 | #endif | - |
157 | | - |
158 | while(TRUE) | 0 |
159 | { | - |
160 | /* Swap previous characters. */ | - |
161 | while (length-- > 0) never evaluated: length-- > 0 | 0 |
162 | { | - |
163 | *ptr = swap_uint16(*ptr); never executed (the execution status of this line is deduced): *ptr = swap_uint16(*ptr); | - |
164 | ptr++; never executed (the execution status of this line is deduced): ptr++; | - |
165 | } | 0 |
166 | #ifdef SUPPORT_UTF | - |
167 | if (utf16_char) never evaluated: utf16_char | 0 |
168 | { | - |
169 | if (HAS_EXTRALEN(ptr[-1])) never evaluated: (((ptr[-1]) & 0xfc00) == 0xd800) | 0 |
170 | { | - |
171 | /* We know that there is only one extra character in UTF-16. */ | - |
172 | *ptr = swap_uint16(*ptr); never executed (the execution status of this line is deduced): *ptr = swap_uint16(*ptr); | - |
173 | ptr++; never executed (the execution status of this line is deduced): ptr++; | - |
174 | } | 0 |
175 | } | 0 |
176 | utf16_char = FALSE; never executed (the execution status of this line is deduced): utf16_char = 0; | - |
177 | #endif /* SUPPORT_UTF */ | - |
178 | | - |
179 | /* Get next opcode. */ | - |
180 | length = 0; never executed (the execution status of this line is deduced): length = 0; | - |
181 | *ptr = swap_uint16(*ptr); never executed (the execution status of this line is deduced): *ptr = swap_uint16(*ptr); | - |
182 | switch (*ptr) | - |
183 | { | - |
184 | case OP_END: | - |
185 | return 0; never executed: return 0; | 0 |
186 | | - |
187 | #ifdef SUPPORT_UTF | - |
188 | case OP_CHAR: | - |
189 | case OP_CHARI: | - |
190 | case OP_NOT: | - |
191 | case OP_NOTI: | - |
192 | case OP_STAR: | - |
193 | case OP_MINSTAR: | - |
194 | case OP_PLUS: | - |
195 | case OP_MINPLUS: | - |
196 | case OP_QUERY: | - |
197 | case OP_MINQUERY: | - |
198 | case OP_UPTO: | - |
199 | case OP_MINUPTO: | - |
200 | case OP_EXACT: | - |
201 | case OP_POSSTAR: | - |
202 | case OP_POSPLUS: | - |
203 | case OP_POSQUERY: | - |
204 | case OP_POSUPTO: | - |
205 | case OP_STARI: | - |
206 | case OP_MINSTARI: | - |
207 | case OP_PLUSI: | - |
208 | case OP_MINPLUSI: | - |
209 | case OP_QUERYI: | - |
210 | case OP_MINQUERYI: | - |
211 | case OP_UPTOI: | - |
212 | case OP_MINUPTOI: | - |
213 | case OP_EXACTI: | - |
214 | case OP_POSSTARI: | - |
215 | case OP_POSPLUSI: | - |
216 | case OP_POSQUERYI: | - |
217 | case OP_POSUPTOI: | - |
218 | case OP_NOTSTAR: | - |
219 | case OP_NOTMINSTAR: | - |
220 | case OP_NOTPLUS: | - |
221 | case OP_NOTMINPLUS: | - |
222 | case OP_NOTQUERY: | - |
223 | case OP_NOTMINQUERY: | - |
224 | case OP_NOTUPTO: | - |
225 | case OP_NOTMINUPTO: | - |
226 | case OP_NOTEXACT: | - |
227 | case OP_NOTPOSSTAR: | - |
228 | case OP_NOTPOSPLUS: | - |
229 | case OP_NOTPOSQUERY: | - |
230 | case OP_NOTPOSUPTO: | - |
231 | case OP_NOTSTARI: | - |
232 | case OP_NOTMINSTARI: | - |
233 | case OP_NOTPLUSI: | - |
234 | case OP_NOTMINPLUSI: | - |
235 | case OP_NOTQUERYI: | - |
236 | case OP_NOTMINQUERYI: | - |
237 | case OP_NOTUPTOI: | - |
238 | case OP_NOTMINUPTOI: | - |
239 | case OP_NOTEXACTI: | - |
240 | case OP_NOTPOSSTARI: | - |
241 | case OP_NOTPOSPLUSI: | - |
242 | case OP_NOTPOSQUERYI: | - |
243 | case OP_NOTPOSUPTOI: | - |
244 | if (utf) utf16_char = TRUE; never executed: utf16_char = 1; never evaluated: utf | 0 |
245 | #endif | - |
246 | /* Fall through. */ | - |
247 | | - |
248 | default: code before this statement never executed: default: | 0 |
249 | length = PRIV(OP_lengths)[*ptr] - 1; never executed (the execution status of this line is deduced): length = _pcre16_OP_lengths[*ptr] - 1; | - |
250 | break; | 0 |
251 | | - |
252 | case OP_CLASS: | - |
253 | case OP_NCLASS: | - |
254 | /* Skip the character bit map. */ | - |
255 | ptr += 32/sizeof(pcre_uchar); never executed (the execution status of this line is deduced): ptr += 32/sizeof(pcre_uchar); | - |
256 | length = 0; never executed (the execution status of this line is deduced): length = 0; | - |
257 | break; | 0 |
258 | | - |
259 | case OP_XCLASS: | - |
260 | /* Reverse the size of the XCLASS instance. */ | - |
261 | ptr++; never executed (the execution status of this line is deduced): ptr++; | - |
262 | *ptr = swap_uint16(*ptr); never executed (the execution status of this line is deduced): *ptr = swap_uint16(*ptr); | - |
263 | if (LINK_SIZE > 1) | 0 |
264 | { | - |
265 | /* LINK_SIZE can be 1 or 2 in 16 bit mode. */ | - |
266 | ptr++; never executed (the execution status of this line is deduced): ptr++; | - |
267 | *ptr = swap_uint16(*ptr); never executed (the execution status of this line is deduced): *ptr = swap_uint16(*ptr); | - |
268 | } | 0 |
269 | ptr++; never executed (the execution status of this line is deduced): ptr++; | - |
270 | length = (GET(ptr, -LINK_SIZE)) - (1 + LINK_SIZE + 1); never executed (the execution status of this line is deduced): length = ((ptr[-1])) - (1 + 1 + 1); | - |
271 | *ptr = swap_uint16(*ptr); never executed (the execution status of this line is deduced): *ptr = swap_uint16(*ptr); | - |
272 | if ((*ptr & XCL_MAP) != 0) never evaluated: (*ptr & 0x02) != 0 | 0 |
273 | { | - |
274 | /* Skip the character bit map. */ | - |
275 | ptr += 32/sizeof(pcre_uchar); never executed (the execution status of this line is deduced): ptr += 32/sizeof(pcre_uchar); | - |
276 | length -= 32/sizeof(pcre_uchar); never executed (the execution status of this line is deduced): length -= 32/sizeof(pcre_uchar); | - |
277 | } | 0 |
278 | break; | 0 |
279 | } | - |
280 | ptr++; never executed (the execution status of this line is deduced): ptr++; | - |
281 | } | 0 |
282 | /* Control should never reach here in 16 bit mode. */ | - |
283 | #endif /* !COMPILE_PCRE8 */ | - |
284 | | - |
285 | return 0; never executed: return 0; | 0 |
286 | } | - |
287 | | - |
288 | /* End of pcre_byte_order.c */ | - |
289 | | - |
| | |