diff options
| author | David Lamparter <equinox@diac24.net> | 2019-06-04 17:07:57 +0200 | 
|---|---|---|
| committer | David Lamparter <equinox@diac24.net> | 2019-06-12 19:22:59 +0200 | 
| commit | 3779776a39d81168b701b2cc2ce50a3b2331d3e8 (patch) | |
| tree | 57d3126699bf2e56509b085f370eee899cfe8ab5 /lib | |
| parent | 72ad94d5482298a7bb8d099bee3b7bfeab2a222b (diff) | |
lib/clippy: error out on unsupported bits
clippy can't process #ifdef or similar bits inside of an argument list
(e.g. within the braces of a DEFUN or DEFPY statement.)  Improve error
reporting to catch these cases instead of generating broken C code.
Fixes: #3840
Signed-off-by: David Lamparter <equinox@diac24.net>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/clippy.c | 2 | ||||
| -rw-r--r-- | lib/defun_lex.l | 17 | 
2 files changed, 15 insertions, 4 deletions
diff --git a/lib/clippy.c b/lib/clippy.c index 44dcc02eb8..cd8067f5eb 100644 --- a/lib/clippy.c +++ b/lib/clippy.c @@ -85,8 +85,6 @@ int main(int argc, char **argv)  	if (PyRun_AnyFile(fp, pyfile)) {  		if (PyErr_Occurred())  			PyErr_Print(); -		else -			printf("unknown python failure (?)\n");  		return 1;  	}  	Py_Finalize(); diff --git a/lib/defun_lex.l b/lib/defun_lex.l index 6c0805a4fa..19b06f51b8 100644 --- a/lib/defun_lex.l +++ b/lib/defun_lex.l @@ -163,7 +163,7 @@ static int yylex_clr(char **retbuf)  	return rv;  } -static PyObject *get_args(void) +static PyObject *get_args(const char *filename, int lineno)  {  	PyObject *pyObj = PyList_New(0);  	PyObject *pyArg = NULL; @@ -190,6 +190,13 @@ static PyObject *get_args(void)  			free(tval);  			continue;  		} +		if (token == PREPROC) { +			free(tval); +			Py_DECREF(pyObj); +			return PyErr_Format(PyExc_ValueError, +					"%s:%d: cannot process CPP directive within argument list", +					filename, lineno); +		}  		if (token == SPECIAL) {  			if (depth == 1 && (tval[0] == ',' || tval[0] == ')')) {  				if (pyArg) @@ -244,7 +251,12 @@ PyObject *clippy_parse(PyObject *self, PyObject *args)  		case DEFUNNY:  		case INSTALL:  		case AUXILIARY: -			pyArgs = get_args(); +			pyArgs = get_args(filename, lineno); +			if (!pyArgs) { +				free(tval); +				Py_DECREF(pyCont); +				return NULL; +			}  			pyItem = PyDict_New();  			PyDict_SetItemString(pyItem, "type", PyUnicode_FromString(tval));  			PyDict_SetItemString(pyItem, "args", pyArgs); @@ -260,6 +272,7 @@ PyObject *clippy_parse(PyObject *self, PyObject *args)  			pyItem = PyDict_New();  			PyDict_SetItemString(pyItem, "type", PyUnicode_FromString("PREPROC"));  			PyDict_SetItemString(pyItem, "line", PyUnicode_FromString(tval)); +			lineno--;  			break;  		}  		if (pyItem) {  | 
