... | ... |
@@ -162,9 +162,9 @@ cl_error_t cli_pcre_compile(struct cli_pcre_data *pd, long long unsigned match_l |
162 | 162 |
|
163 | 163 |
/* compile the pcre2 regex last arg is charset, allow for options override */ |
164 | 164 |
if (opt_override) |
165 |
- pd->re = pcre2_compile(pd->expression, PCRE2_ZERO_TERMINATED, options, &errornum, &erroffset, cctx); /* pd->re handled by pcre2 -> call pcre_free() -> calls free() */ |
|
165 |
+ pd->re = pcre2_compile((PCRE2_SPTR8)pd->expression, PCRE2_ZERO_TERMINATED, options, &errornum, &erroffset, cctx); /* pd->re handled by pcre2 -> call pcre_free() -> calls free() */ |
|
166 | 166 |
else |
167 |
- pd->re = pcre2_compile(pd->expression, PCRE2_ZERO_TERMINATED, pd->options, &errornum, &erroffset, cctx); /* pd->re handled by pcre2 -> call pcre_free() -> calls free() */ |
|
167 |
+ pd->re = pcre2_compile((PCRE2_SPTR8)pd->expression, PCRE2_ZERO_TERMINATED, pd->options, &errornum, &erroffset, cctx); /* pd->re handled by pcre2 -> call pcre_free() -> calls free() */ |
|
168 | 168 |
if (pd->re == NULL) { |
169 | 169 |
PCRE2_UCHAR errmsg[256]; |
170 | 170 |
pcre2_get_error_message(errornum, errmsg, sizeof(errmsg)); |
... | ... |
@@ -246,17 +246,20 @@ cl_error_t cli_pcre_compile(struct cli_pcre_data *pd, long long unsigned match_l |
246 | 246 |
} |
247 | 247 |
#endif |
248 | 248 |
|
249 |
-int cli_pcre_match(struct cli_pcre_data *pd, const unsigned char *buffer, uint32_t buflen, int override_offset, int options, struct cli_pcre_results *results) |
|
249 |
+int cli_pcre_match(struct cli_pcre_data *pd, const unsigned char *buffer, size_t buflen, size_t override_offset, int options, struct cli_pcre_results *results) |
|
250 | 250 |
{ |
251 |
- int rc, startoffset; |
|
251 |
+ int rc; |
|
252 |
+ |
|
252 | 253 |
#if USING_PCRE2 |
253 |
- pcre2_general_context *pc2ctx; |
|
254 | 254 |
PCRE2_SIZE *ovector; |
255 |
+ size_t startoffset; |
|
256 |
+#else |
|
257 |
+ int startoffset; |
|
255 | 258 |
#endif |
256 | 259 |
|
257 | 260 |
/* set the startoffset, override if a value is specified */ |
258 | 261 |
startoffset = pd->search_offset; |
259 |
- if (override_offset >= 0) |
|
262 |
+ if (override_offset != pd->search_offset) |
|
260 | 263 |
startoffset = override_offset; |
261 | 264 |
|
262 | 265 |
/* execute the pcre and return */ |
... | ... |
@@ -289,7 +292,7 @@ int cli_pcre_match(struct cli_pcre_data *pd, const unsigned char *buffer, uint32 |
289 | 289 |
results->match[0] = results->match[1] = 0; |
290 | 290 |
} |
291 | 291 |
#else |
292 |
- rc = pcre_exec(pd->re, pd->ex, (const char *)buffer, buflen, startoffset, options, results->ovector, OVECCOUNT); |
|
292 |
+ rc = pcre_exec(pd->re, pd->ex, (const char *)buffer, (int)buflen, (int)startoffset, options, results->ovector, OVECCOUNT); |
|
293 | 293 |
if (rc < 0 && rc != PCRE_ERROR_NOMATCH) { |
294 | 294 |
switch (rc) { |
295 | 295 |
case PCRE_ERROR_CALLOUT: |
... | ... |
@@ -322,9 +325,20 @@ int cli_pcre_match(struct cli_pcre_data *pd, const unsigned char *buffer, uint32 |
322 | 322 |
#define MATCH_MAXLEN 1028 /*because lolz*/ |
323 | 323 |
|
324 | 324 |
/* TODO: audit this function */ |
325 |
+#if USING_PCRE2 |
|
326 |
+static void named_substr_print(const struct cli_pcre_data *pd, const unsigned char *buffer, PCRE2_SIZE *ovector) |
|
327 |
+#else |
|
325 | 328 |
static void named_substr_print(const struct cli_pcre_data *pd, const unsigned char *buffer, int *ovector) |
329 |
+#endif |
|
326 | 330 |
{ |
327 |
- int i, j, length, namecount, trunc; |
|
331 |
+ int i, namecount, trunc; |
|
332 |
+ |
|
333 |
+#if USING_PCRE2 |
|
334 |
+ PCRE2_SIZE length, j; |
|
335 |
+#else |
|
336 |
+ int length, j; |
|
337 |
+#endif |
|
338 |
+ |
|
328 | 339 |
unsigned char *tabptr; |
329 | 340 |
int name_entry_size; |
330 | 341 |
unsigned char *name_table; |
... | ... |
@@ -380,11 +394,19 @@ static void named_substr_print(const struct cli_pcre_data *pd, const unsigned ch |
380 | 380 |
} |
381 | 381 |
|
382 | 382 |
/* TODO: audit this function */ |
383 |
-void cli_pcre_report(const struct cli_pcre_data *pd, const unsigned char *buffer, uint32_t buflen, int rc, struct cli_pcre_results *results) |
|
383 |
+void cli_pcre_report(const struct cli_pcre_data *pd, const unsigned char *buffer, size_t buflen, int rc, struct cli_pcre_results *results) |
|
384 | 384 |
{ |
385 |
- int i, j, length, trunc; |
|
385 |
+ int i, trunc; |
|
386 |
+ |
|
387 |
+#if USING_PCRE2 |
|
388 |
+ PCRE2_SIZE length, j; |
|
389 |
+#else |
|
390 |
+ int length, j; |
|
391 |
+#endif |
|
392 |
+ |
|
386 | 393 |
const char *start; |
387 | 394 |
char outstr[2 * MATCH_MAXLEN + 1]; |
395 |
+ |
|
388 | 396 |
#if USING_PCRE2 |
389 | 397 |
PCRE2_SIZE *ovector; |
390 | 398 |
ovector = pcre2_get_ovector_pointer(results->match_data); |
... | ... |
@@ -407,7 +429,11 @@ void cli_pcre_report(const struct cli_pcre_data *pd, const unsigned char *buffer |
407 | 407 |
start = (const char *)buffer + ovector[2 * i]; |
408 | 408 |
length = ovector[2 * i + 1] - ovector[2 * i]; |
409 | 409 |
|
410 |
+#ifdef USING_PCRE2 |
|
410 | 411 |
if (ovector[2 * i + 1] > buflen) { |
412 |
+#else |
|
413 |
+ if (ovector[2 * i + 1] > (int)buflen) { |
|
414 |
+#endif |
|
411 | 415 |
cli_warnmsg("cli_pcre_report: reported match goes outside buffer\n"); |
412 | 416 |
continue; |
413 | 417 |
} |
... | ... |
@@ -79,8 +79,8 @@ struct cli_pcre_results { |
79 | 79 |
cl_error_t cli_pcre_init_internal(); |
80 | 80 |
cl_error_t cli_pcre_addoptions(struct cli_pcre_data *pd, const char **opt, int errout); |
81 | 81 |
cl_error_t cli_pcre_compile(struct cli_pcre_data *pd, long long unsigned match_limit, long long unsigned match_limit_recursion, unsigned int options, int opt_override); |
82 |
-int cli_pcre_match(struct cli_pcre_data *pd, const unsigned char *buffer, uint32_t buflen, int override_offset, int options, struct cli_pcre_results *results); |
|
83 |
-void cli_pcre_report(const struct cli_pcre_data *pd, const unsigned char *buffer, uint32_t buflen, int rc, struct cli_pcre_results *results); |
|
82 |
+int cli_pcre_match(struct cli_pcre_data *pd, const unsigned char *buffer, size_t buflen, size_t override_offset, int options, struct cli_pcre_results *results); |
|
83 |
+void cli_pcre_report(const struct cli_pcre_data *pd, const unsigned char *buffer, size_t buflen, int rc, struct cli_pcre_results *results); |
|
84 | 84 |
|
85 | 85 |
cl_error_t cli_pcre_results_reset(struct cli_pcre_results *results, const struct cli_pcre_data *pd); |
86 | 86 |
void cli_pcre_results_free(struct cli_pcre_results *results); |