Skip to content

Commit 41de7ff

Browse files
committed
improve output for clarity
1 parent 273f7ce commit 41de7ff

File tree

1 file changed

+46
-32
lines changed

1 file changed

+46
-32
lines changed

src/pcre2_fuzzsupport.c

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,10 @@ static void describe_failure(
123123
uint32_t compile_options,
124124
uint32_t match_options,
125125
int errorcode,
126-
pcre2_match_data *match_data,
127126
int errorcode_jit,
127+
int matches,
128+
int matches_jit,
129+
pcre2_match_data *match_data,
128130
pcre2_match_data *match_data_jit,
129131
pcre2_match_context *match_context
130132
) {
@@ -145,31 +147,31 @@ print_match_options(stderr, match_options);
145147
if (errorcode < 0)
146148
{
147149
pcre2_get_error_message(errorcode, buffer, 256);
148-
fprintf(stderr, "Non-JIT'd operation emitted an error: %s\n", buffer);
150+
fprintf(stderr, "Non-JIT'd operation emitted an error: %s (%d)\n", buffer, errorcode);
149151
}
150-
else
152+
if (matches >= 0)
151153
{
152154
fprintf(stderr, "Non-JIT'd operation did not emit an error.\n");
153155
if (match_data != NULL)
154156
{
155-
fprintf(stderr, "%d matches discovered by non-JIT'd regex:\n", errorcode);
156-
dump_matches(stderr, errorcode, match_data, match_context);
157+
fprintf(stderr, "%d matches discovered by non-JIT'd regex:\n", matches);
158+
dump_matches(stderr, matches, match_data, match_context);
157159
fprintf(stderr, "\n");
158160
}
159161
}
160162

161163
if (errorcode_jit < 0)
162164
{
163165
pcre2_get_error_message(errorcode_jit, buffer, 256);
164-
fprintf(stderr, "JIT'd operation emitted an error: %s\n", buffer);
166+
fprintf(stderr, "JIT'd operation emitted an error: %s (%d)\n", buffer, errorcode_jit);
165167
}
166-
else
168+
if (matches_jit >= 0)
167169
{
168170
fprintf(stderr, "JIT'd operation did not emit an error.\n");
169171
if (match_data_jit != NULL)
170172
{
171-
fprintf(stderr, "%d matches discovered by JIT'd regex:\n", errorcode_jit);
172-
dump_matches(stderr, errorcode_jit, match_data_jit, match_context);
173+
fprintf(stderr, "%d matches discovered by JIT'd regex:\n", matches_jit);
174+
dump_matches(stderr, matches_jit, match_data_jit, match_context);
173175
fprintf(stderr, "\n");
174176
}
175177
}
@@ -246,6 +248,8 @@ for (i = 0; i < 2; i++)
246248
int errorcode;
247249
#ifdef SUPPORT_JIT
248250
int errorcode_jit;
251+
int matches = 0;
252+
int matches_jit = 0;
249253
#endif
250254
PCRE2_SIZE erroroffset;
251255
pcre2_code *code;
@@ -332,42 +336,52 @@ for (i = 0; i < 2; i++)
332336
errorcode_jit = pcre2_match(code, (PCRE2_SPTR)data, (PCRE2_SIZE)match_size, 0,
333337
match_options & ~PCRE2_NO_JIT, match_data_jit, match_context);
334338

339+
matches = errorcode;
340+
matches_jit = errorcode_jit;
341+
335342
if (errorcode_jit != errorcode)
336343
{
337-
describe_failure("match errorcode comparison", data, size, compile_options, match_options, errorcode, match_data, errorcode_jit, match_data_jit, match_context);
344+
if (!(errorcode < 0 && errorcode_jit < 0) &&
345+
errorcode != PCRE2_ERROR_MATCHLIMIT &&
346+
errorcode_jit != PCRE2_ERROR_MATCHLIMIT && errorcode_jit != PCRE2_ERROR_JIT_STACKLIMIT)
347+
{
348+
describe_failure("match errorcode comparison", data, size, compile_options, match_options, errorcode, errorcode_jit, matches, matches_jit, match_data, match_data_jit, match_context);
349+
}
338350
}
339-
340-
for (int index = 0; index < errorcode; index++)
351+
else
341352
{
342-
PCRE2_UCHAR *bufferptr, *bufferptr_jit;
343-
PCRE2_SIZE bufflen, bufflen_jit;
344-
345-
bufferptr = bufferptr_jit = NULL;
346-
bufflen = bufflen_jit = 0;
353+
for (int index = 0; index < errorcode; index++)
354+
{
355+
PCRE2_UCHAR *bufferptr, *bufferptr_jit;
356+
PCRE2_SIZE bufflen, bufflen_jit;
347357

348-
errorcode = pcre2_substring_get_bynumber(match_data, (uint32_t) index, &bufferptr, &bufflen);
349-
errorcode_jit = pcre2_substring_get_bynumber(match_data_jit, (uint32_t) index, &bufferptr_jit, &bufflen_jit);
358+
bufferptr = bufferptr_jit = NULL;
359+
bufflen = bufflen_jit = 0;
350360

351-
if (errorcode != errorcode_jit)
352-
{
353-
describe_failure("ovector entry errorcode comparison", data, size, compile_options, match_options, errorcode, match_data, errorcode_jit, match_data_jit, match_context);
354-
}
361+
errorcode = pcre2_substring_get_bynumber(match_data, (uint32_t) index, &bufferptr, &bufflen);
362+
errorcode_jit = pcre2_substring_get_bynumber(match_data_jit, (uint32_t) index, &bufferptr_jit, &bufflen_jit);
355363

356-
if (errorcode >= 0)
357-
{
358-
if (bufflen != bufflen_jit)
364+
if (errorcode != errorcode_jit)
359365
{
360-
describe_failure("ovector entry length comparison", data, size, compile_options, match_options, errorcode, match_data, errorcode_jit, match_data_jit, match_context);
366+
describe_failure("match entry errorcode comparison", data, size, compile_options, match_options, errorcode, errorcode_jit, matches, matches_jit, match_data, match_data_jit, match_context);
361367
}
362368

363-
if (memcmp(bufferptr, bufferptr_jit, bufflen) != 0)
369+
if (errorcode >= 0)
364370
{
365-
describe_failure("ovector entry content comparison", data, size, compile_options, match_options, errorcode, match_data, errorcode_jit, match_data_jit, match_context);
371+
if (bufflen != bufflen_jit)
372+
{
373+
describe_failure("match entry length comparison", data, size, compile_options, match_options, errorcode, errorcode_jit, matches, matches_jit, match_data, match_data_jit, match_context);
374+
}
375+
376+
if (memcmp(bufferptr, bufferptr_jit, bufflen) != 0)
377+
{
378+
describe_failure("match entry content comparison", data, size, compile_options, match_options, errorcode, errorcode_jit, matches, matches_jit, match_data, match_data_jit, match_context);
379+
}
366380
}
367-
}
368381

369-
pcre2_substring_free(bufferptr);
370-
pcre2_substring_free(bufferptr_jit);
382+
pcre2_substring_free(bufferptr);
383+
pcre2_substring_free(bufferptr_jit);
384+
}
371385
}
372386
}
373387
#endif

0 commit comments

Comments
 (0)