@@ -188,37 +188,33 @@ static int fuzz_json_loads(const char* data, size_t size) {
188188
189189#define MAX_RE_TEST_SIZE 0x10000
190190
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 ;
194194/* Called by LLVMFuzzerTestOneInput for initialization */
195195static int init_sre_compile (void ) {
196196 /* 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 ) {
199199 return 0 ;
200200 }
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 ) {
203203 return 0 ;
204204 }
205205
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 ) {
208208 return 0 ;
209209 }
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" );
215211 if (debug_flag == NULL ) {
216212 return 0 ;
217213 }
218- SRE_FLAG_DEBUG = PyLong_AsLong (debug_flag );
214+ RE_FLAG_DEBUG = PyLong_AsLong (debug_flag );
219215 return 1 ;
220216}
221- /* Fuzz _sre .compile(x) */
217+ /* Fuzz re .compile(x) */
222218static int fuzz_sre_compile (const char * data , size_t size ) {
223219 /* Ignore really long regex patterns that will timeout the fuzzer */
224220 if (size > MAX_RE_TEST_SIZE ) {
@@ -231,7 +227,7 @@ static int fuzz_sre_compile(const char* data, size_t size) {
231227 uint16_t flags = ((uint16_t * ) data )[0 ];
232228 /* We remove the SRE_FLAG_DEBUG if present. This is because it
233229 prints to stdout which greatly decreases fuzzing speed */
234- flags &= ~SRE_FLAG_DEBUG ;
230+ flags &= ~RE_FLAG_DEBUG ;
235231
236232 /* Pull the pattern from the remaining bytes */
237233 PyObject * pattern_bytes = PyBytes_FromStringAndSize (data + 2 , size - 2 );
@@ -244,9 +240,9 @@ static int fuzz_sre_compile(const char* data, size_t size) {
244240 return 0 ;
245241 }
246242
247- /* compiled = _sre .compile(data[2:], data[0:2] */
243+ /* compiled = re .compile(data[2:], data[0:2] */
248244 PyObject * compiled = PyObject_CallFunctionObjArgs (
249- sre_compile_method , pattern_bytes , flags_obj , NULL );
245+ re_compile_method , pattern_bytes , flags_obj , NULL );
250246 /* Ignore ValueError as the fuzzer will more than likely
251247 generate some invalid combination of flags */
252248 if (compiled == NULL && PyErr_ExceptionMatches (PyExc_ValueError )) {
@@ -262,7 +258,7 @@ static int fuzz_sre_compile(const char* data, size_t size) {
262258 PyErr_Clear ();
263259 }
264260 /* Ignore re.error */
265- if (compiled == NULL && PyErr_ExceptionMatches (sre_error_exception )) {
261+ if (compiled == NULL && PyErr_ExceptionMatches (re_error_exception )) {
266262 PyErr_Clear ();
267263 }
268264
@@ -526,13 +522,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
526522#if !defined(_Py_FUZZ_ONE ) || defined(_Py_FUZZ_fuzz_sre_compile )
527523 static int SRE_COMPILE_INITIALIZED = 0 ;
528524 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 ();
536527 } else {
537528 SRE_COMPILE_INITIALIZED = 1 ;
538529 }
0 commit comments