fuzz: report error if Python code raised exception
authorYuya Nishihara <yuya@tcha.org>
Tue, 09 Oct 2018 07:46:01 +0900
changeset 40100 ca4a32d0a4d6
parent 40099 994010b87534
child 40101 57500950f40e
fuzz: report error if Python code raised exception I think that's what we wanted to do, given the most of the code block is surrounded by try-except. 'lazymanifest(mdata)' is moved to the try block as it can fail.
contrib/fuzz/manifest.cc
--- a/contrib/fuzz/manifest.cc	Tue Oct 09 07:42:05 2018 +0900
+++ b/contrib/fuzz/manifest.cc	Tue Oct 09 07:46:01 2018 +0900
@@ -47,8 +47,8 @@
 	PyCodeObject *code =
 	    (PyCodeObject *)Py_CompileString(R"py(
 from parsers import lazymanifest
-lm = lazymanifest(mdata)
 try:
+  lm = lazymanifest(mdata)
   # iterate the whole thing, which causes the code to fully parse
   # every line in the manifest
   list(lm.iterentries())
@@ -65,7 +65,11 @@
   # print e
 )py",
 	                                     "fuzzer", Py_file_input);
-	PyEval_EvalCode(code, globals, locals);
+	PyObject *res = PyEval_EvalCode(code, globals, locals);
+	if (!res) {
+		PyErr_Print();
+	}
+	Py_XDECREF(res);
 	Py_DECREF(code);
 	Py_DECREF(locals);
 	Py_DECREF(mtext);