Skip to content

Commit 63ddad8

Browse files
committed
support 8-, 16-, and 32-bit modes
1 parent 0c92eb3 commit 63ddad8

File tree

3 files changed

+82
-12
lines changed

3 files changed

+82
-12
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ pcre2posix_test.exe
5050
pcre2posix_test.log
5151
pcre2posix_test.trs
5252
pcre2demo
53-
pcre2fuzzcheck
53+
pcre2fuzzcheck-*
54+
pcre2fuzzer-*
5455
pcre2grep
5556
pcre2grep.exe
5657
pcre2test

Makefile.am

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -540,28 +540,64 @@ if WITH_GCOV
540540
pcre2grep_CFLAGS += $(GCOV_CFLAGS)
541541
pcre2grep_LDADD += $(GCOV_LIBS)
542542
endif # WITH_GCOV
543+
endif # WITH_PCRE2_8
543544

544545
## If fuzzer support is enabled, build a non-distributed library containing the
545546
## fuzzing function. Also build the standalone checking binary from the same
546547
## source but using -DSTANDALONE.
547548

548549
if WITH_FUZZ_SUPPORT
549-
noinst_LIBRARIES = .libs/libpcre2-fuzzsupport.a
550+
noinst_LIBRARIES =
551+
if WITH_PCRE2_8
552+
noinst_LIBRARIES += .libs/libpcre2-fuzzsupport.a
550553
_libs_libpcre2_fuzzsupport_a_SOURCES = src/pcre2_fuzzsupport.c
551554
_libs_libpcre2_fuzzsupport_a_CFLAGS = $(AM_CFLAGS)
552555
_libs_libpcre2_fuzzsupport_a_LIBADD =
553556

554-
noinst_PROGRAMS += pcre2fuzzcheck
555-
pcre2fuzzcheck_SOURCES = src/pcre2_fuzzsupport.c
556-
pcre2fuzzcheck_CFLAGS = -DSTANDALONE $(AM_CFLAGS)
557-
pcre2fuzzcheck_LDADD = libpcre2-8.la
557+
noinst_PROGRAMS += pcre2fuzzcheck-8
558+
pcre2fuzzcheck_8_SOURCES = src/pcre2_fuzzsupport.c
559+
pcre2fuzzcheck_8_CFLAGS = -DSTANDALONE $(AM_CFLAGS)
560+
pcre2fuzzcheck_8_LDADD = libpcre2-8.la
558561
if WITH_GCOV
559-
pcre2fuzzcheck_CFLAGS += $(GCOV_CFLAGS)
560-
pcre2fuzzcheck_LDADD += $(GCOV_LIBS)
562+
pcre2fuzzcheck_8_CFLAGS += $(GCOV_CFLAGS)
563+
pcre2fuzzcheck_8_LDADD += $(GCOV_LIBS)
561564
endif # WITH_GCOV
562-
endif # WITH FUZZ_SUPPORT
563565
endif # WITH_PCRE2_8
564566

567+
if WITH_PCRE2_16
568+
noinst_LIBRARIES += .libs/libpcre2-fuzzsupport-16.a
569+
_libs_libpcre2_fuzzsupport_16_a_SOURCES = src/pcre2_fuzzsupport.c
570+
_libs_libpcre2_fuzzsupport_16_a_CFLAGS = $(AM_CFLAGS) -DPCRE2_CODE_UNIT_WIDTH=16
571+
_libs_libpcre2_fuzzsupport_16_a_LIBADD =
572+
573+
noinst_PROGRAMS += pcre2fuzzcheck-16
574+
pcre2fuzzcheck_16_SOURCES = src/pcre2_fuzzsupport.c
575+
pcre2fuzzcheck_16_CFLAGS = -DSTANDALONE $(AM_CFLAGS) -DPCRE2_CODE_UNIT_WIDTH=16
576+
pcre2fuzzcheck_16_LDADD = libpcre2-16.la
577+
if WITH_GCOV
578+
pcre2fuzzcheck_16_CFLAGS += $(GCOV_CFLAGS)
579+
pcre2fuzzcheck_16_LDADD += $(GCOV_LIBS)
580+
endif # WITH_GCOV
581+
endif # WITH_PCRE2_16
582+
583+
if WITH_PCRE2_32
584+
noinst_LIBRARIES += .libs/libpcre2-fuzzsupport-32.a
585+
_libs_libpcre2_fuzzsupport_32_a_SOURCES = src/pcre2_fuzzsupport.c
586+
_libs_libpcre2_fuzzsupport_32_a_CFLAGS = $(AM_CFLAGS) -DPCRE2_CODE_UNIT_WIDTH=32
587+
_libs_libpcre2_fuzzsupport_32_a_LIBADD =
588+
589+
noinst_PROGRAMS += pcre2fuzzcheck-32
590+
pcre2fuzzcheck_32_SOURCES = src/pcre2_fuzzsupport.c
591+
pcre2fuzzcheck_32_CFLAGS = -DSTANDALONE $(AM_CFLAGS) -DPCRE2_CODE_UNIT_WIDTH=32
592+
pcre2fuzzcheck_32_LDADD = libpcre2-32.la
593+
if WITH_GCOV
594+
pcre2fuzzcheck_32_CFLAGS += $(GCOV_CFLAGS)
595+
pcre2fuzzcheck_32_LDADD += $(GCOV_LIBS)
596+
endif # WITH_GCOV
597+
endif # WITH_PCRE2_32
598+
599+
endif # WITH_FUZZ_SUPPORT
600+
565601
## -------- Testing ----------
566602

567603
## If the 8-bit library is enabled, build the POSIX wrapper test program and

src/pcre2_fuzzsupport.c

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ Written by Philip Hazel, October 2016
1414
#include <stdlib.h>
1515
#include <string.h>
1616

17-
#include "config.h"
17+
#ifndef PCRE2_CODE_UNIT_WIDTH
1818
#define PCRE2_CODE_UNIT_WIDTH 8
19+
#endif
20+
21+
#include "config.h"
1922
#include "pcre2.h"
2023

2124
#define MAX_MATCH_SIZE 1000
@@ -86,7 +89,9 @@ fprintf(stream, "%s%s%s%s%s%s%s%s%s\n",
8689

8790
static void dump_matches(FILE *stream, int count, pcre2_match_data *match_data, pcre2_match_context *match_context)
8891
{
92+
#if PCRE2_CODE_UNIT_WIDTH == 8
8993
PCRE2_UCHAR error_buf[256];
94+
#endif
9095
int errorcode;
9196

9297
for (uint32_t index = 0; index < count; index++)
@@ -107,8 +112,12 @@ for (uint32_t index = 0; index < count; index++)
107112
}
108113
else
109114
{
115+
#if PCRE2_CODE_UNIT_WIDTH == 8
110116
pcre2_get_error_message(errorcode, error_buf, 256);
111117
fprintf(stream, "Match %d failed: %s\n", index, error_buf);
118+
#else
119+
fprintf(stream, "Match %d failed: %d\n", index, errorcode);
120+
#endif
112121
}
113122
}
114123
}
@@ -130,7 +139,9 @@ static void describe_failure(
130139
pcre2_match_data *match_data_jit,
131140
pcre2_match_context *match_context
132141
) {
142+
#if PCRE2_CODE_UNIT_WIDTH == 8
133143
PCRE2_UCHAR buffer[256];
144+
#endif
134145

135146
fprintf(stderr, "Encountered failure while performing %s; context:\n", task);
136147

@@ -146,8 +157,12 @@ print_match_options(stderr, match_options);
146157

147158
if (errorcode < 0)
148159
{
160+
#if PCRE2_CODE_UNIT_WIDTH == 8
149161
pcre2_get_error_message(errorcode, buffer, 256);
150162
fprintf(stderr, "Non-JIT'd operation emitted an error: %s (%d)\n", buffer, errorcode);
163+
#else
164+
fprintf(stderr, "Non-JIT'd operation emitted an error: %d\n", errorcode);
165+
#endif
151166
}
152167
if (matches >= 0)
153168
{
@@ -162,8 +177,12 @@ if (matches >= 0)
162177

163178
if (errorcode_jit < 0)
164179
{
180+
#if PCRE2_CODE_UNIT_WIDTH == 8
165181
pcre2_get_error_message(errorcode_jit, buffer, 256);
166182
fprintf(stderr, "JIT'd operation emitted an error: %s (%d)\n", buffer, errorcode_jit);
183+
#else
184+
fprintf(stderr, "JIT'd operation emitted an error: %d\n", errorcode);
185+
#endif
167186
}
168187
if (matches_jit >= 0)
169188
{
@@ -220,6 +239,7 @@ in large trees taking too much time. */
220239
random_options = *(uint64_t *)(data);
221240
data += sizeof(random_options);
222241
size -= sizeof(random_options);
242+
size /= PCRE2_CODE_UNIT_WIDTH / 8;
223243

224244
match_size = (size > MAX_MATCH_SIZE)? MAX_MATCH_SIZE : size;
225245

@@ -323,9 +343,13 @@ for (i = 0; i < 2; i++)
323343
#ifdef STANDALONE
324344
if (errorcode >= 0) printf("Match returned %d\n", errorcode); else
325345
{
346+
#if PCRE2_CODE_UNIT_WIDTH == 8
326347
unsigned char buffer[256];
327348
pcre2_get_error_message(errorcode, buffer, 256);
328349
printf("Match failed: error %d: %s\n", errorcode, buffer);
350+
#else
351+
printf("Match failed: error %d\n", errorcode);
352+
#endif
329353
}
330354
#endif
331355

@@ -417,9 +441,13 @@ for (i = 0; i < 2; i++)
417441
#ifdef STANDALONE
418442
if (errorcode >= 0) printf("Match returned %d\n", errorcode); else
419443
{
444+
#if PCRE2_CODE_UNIT_WIDTH == 8
420445
unsigned char buffer[256];
421446
pcre2_get_error_message(errorcode, buffer, 256);
422447
printf("Match failed: error %d: %s\n", errorcode, buffer);
448+
#else
449+
printf("Match failed: error %d\n", errorcode);
450+
#endif
423451
}
424452
#endif
425453

@@ -434,12 +462,17 @@ for (i = 0; i < 2; i++)
434462

435463
else
436464
{
465+
#ifdef STANDALONE
466+
#if PCRE2_CODE_UNIT_WIDTH == 8
437467
unsigned char buffer[256];
438468
pcre2_get_error_message(errorcode, buffer, 256);
439-
#ifdef STANDALONE
440469
printf("Error %d at offset %lu: %s\n", errorcode, erroroffset, buffer);
441470
#else
442-
if (strstr((const char *)buffer, "internal error") != NULL) abort();
471+
printf("Error %d at offset %lu\n", errorcode, erroroffset);
472+
#endif
473+
474+
#else
475+
if (errorcode == PCRE2_ERROR_INTERNAL) abort();
443476
#endif
444477
}
445478

0 commit comments

Comments
 (0)