@@ -188,37 +188,33 @@ static int fuzz_json_loads(const char* data, size_t size) {
188
188
189
189
#define MAX_RE_TEST_SIZE 0x10000
190
190
191
- PyObject * sre_compile_method = NULL ;
192
- PyObject * sre_error_exception = NULL ;
193
- int SRE_FLAG_DEBUG = 0 ;
191
+ PyObject * re_compile_method = NULL ;
192
+ PyObject * re_error_exception = NULL ;
193
+ int RE_FLAG_DEBUG = 0 ;
194
194
/* Called by LLVMFuzzerTestOneInput for initialization */
195
195
static int init_sre_compile (void ) {
196
196
/* Import sre_compile.compile and sre.error */
197
- PyObject * sre_compile_module = PyImport_ImportModule ("sre_compile " );
198
- if (sre_compile_module == NULL ) {
197
+ PyObject * re_module = PyImport_ImportModule ("re " );
198
+ if (re_module == NULL ) {
199
199
return 0 ;
200
200
}
201
- sre_compile_method = PyObject_GetAttrString (sre_compile_module , "compile" );
202
- if (sre_compile_method == NULL ) {
201
+ re_compile_method = PyObject_GetAttrString (re_module , "compile" );
202
+ if (re_compile_method == NULL ) {
203
203
return 0 ;
204
204
}
205
205
206
- PyObject * sre_constants = PyImport_ImportModule ( "sre_constants " );
207
- if (sre_constants == NULL ) {
206
+ re_error_exception = PyObject_GetAttrString ( re_module , "error " );
207
+ if (re_error_exception == NULL ) {
208
208
return 0 ;
209
209
}
210
- sre_error_exception = PyObject_GetAttrString (sre_constants , "error" );
211
- if (sre_error_exception == NULL ) {
212
- return 0 ;
213
- }
214
- PyObject * debug_flag = PyObject_GetAttrString (sre_constants , "SRE_FLAG_DEBUG" );
210
+ PyObject * debug_flag = PyObject_GetAttrString (re_module , "DEBUG" );
215
211
if (debug_flag == NULL ) {
216
212
return 0 ;
217
213
}
218
- SRE_FLAG_DEBUG = PyLong_AsLong (debug_flag );
214
+ RE_FLAG_DEBUG = PyLong_AsLong (debug_flag );
219
215
return 1 ;
220
216
}
221
- /* Fuzz _sre .compile(x) */
217
+ /* Fuzz re .compile(x) */
222
218
static int fuzz_sre_compile (const char * data , size_t size ) {
223
219
/* Ignore really long regex patterns that will timeout the fuzzer */
224
220
if (size > MAX_RE_TEST_SIZE ) {
@@ -231,7 +227,7 @@ static int fuzz_sre_compile(const char* data, size_t size) {
231
227
uint16_t flags = ((uint16_t * ) data )[0 ];
232
228
/* We remove the SRE_FLAG_DEBUG if present. This is because it
233
229
prints to stdout which greatly decreases fuzzing speed */
234
- flags &= ~SRE_FLAG_DEBUG ;
230
+ flags &= ~RE_FLAG_DEBUG ;
235
231
236
232
/* Pull the pattern from the remaining bytes */
237
233
PyObject * pattern_bytes = PyBytes_FromStringAndSize (data + 2 , size - 2 );
@@ -244,9 +240,9 @@ static int fuzz_sre_compile(const char* data, size_t size) {
244
240
return 0 ;
245
241
}
246
242
247
- /* compiled = _sre .compile(data[2:], data[0:2] */
243
+ /* compiled = re .compile(data[2:], data[0:2] */
248
244
PyObject * compiled = PyObject_CallFunctionObjArgs (
249
- sre_compile_method , pattern_bytes , flags_obj , NULL );
245
+ re_compile_method , pattern_bytes , flags_obj , NULL );
250
246
/* Ignore ValueError as the fuzzer will more than likely
251
247
generate some invalid combination of flags */
252
248
if (compiled == NULL && PyErr_ExceptionMatches (PyExc_ValueError )) {
@@ -262,7 +258,7 @@ static int fuzz_sre_compile(const char* data, size_t size) {
262
258
PyErr_Clear ();
263
259
}
264
260
/* Ignore re.error */
265
- if (compiled == NULL && PyErr_ExceptionMatches (sre_error_exception )) {
261
+ if (compiled == NULL && PyErr_ExceptionMatches (re_error_exception )) {
266
262
PyErr_Clear ();
267
263
}
268
264
@@ -526,13 +522,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
526
522
#if !defined(_Py_FUZZ_ONE ) || defined(_Py_FUZZ_fuzz_sre_compile )
527
523
static int SRE_COMPILE_INITIALIZED = 0 ;
528
524
if (!SRE_COMPILE_INITIALIZED && !init_sre_compile ()) {
529
- if (!PyErr_ExceptionMatches (PyExc_DeprecationWarning )) {
530
- PyErr_Print ();
531
- abort ();
532
- }
533
- else {
534
- PyErr_Clear ();
535
- }
525
+ PyErr_Print ();
526
+ abort ();
536
527
} else {
537
528
SRE_COMPILE_INITIALIZED = 1 ;
538
529
}
0 commit comments