diff options
author | David Lamparter <equinox@opensourcerouting.org> | 2023-03-25 04:34:35 +0100 |
---|---|---|
committer | David Lamparter <equinox@opensourcerouting.org> | 2023-03-25 04:34:35 +0100 |
commit | be95afe1968b43ccc9e3f267b12043a62f3f0595 (patch) | |
tree | 1e97509b6f300480ff0e5ccc54c9437e0fe79f8e | |
parent | lib/clippy: don't SEGV on invalid tokens in DEFPY (diff) | |
download | frr-be95afe1968b43ccc9e3f267b12043a62f3f0595.tar.xz frr-be95afe1968b43ccc9e3f267b12043a62f3f0595.zip |
lib/clippy: bail out on newline inside string
While C compilers will generally process strings across lines, we really
don't want that. I rather treat this as the indication of the typo it
probably is warn about it than support this odd C edge case.
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
-rw-r--r-- | lib/defun_lex.l | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/defun_lex.l b/lib/defun_lex.l index 81ae497cf..124f86416 100644 --- a/lib/defun_lex.l +++ b/lib/defun_lex.l @@ -53,6 +53,7 @@ int comment_link; char string_end; char *value; +static const char *yyfilename; static void extendbuf(char **what, const char *arg) { @@ -119,8 +120,17 @@ SPECIAL [(),] } } <rstring>\\\n /* ignore */ +<rstring>\n { + fprintf(stderr, + "%s:%d: string continues past the end of the line\n", + yyfilename, yylineno); + free(value); + value = NULL; + BEGIN(INITIAL); + return STRING; + } <rstring>\\. extend(yytext); -<rstring>[^\\\"\']+ extend(yytext); +<rstring>[^\\\"\'\n]+ extend(yytext); "DEFUN" value = strdup(yytext); return DEFUNNY; "DEFUN_NOSH" value = strdup(yytext); return DEFUNNY; @@ -235,6 +245,7 @@ PyObject *clippy_parse(PyObject *self, PyObject *args) int token; yyin = fd; value = NULL; + yyfilename = filename; PyObject *pyCont = PyDict_New(); PyObject *pyObj = PyList_New(0); @@ -252,6 +263,7 @@ PyObject *clippy_parse(PyObject *self, PyObject *args) if (!pyArgs) { free(tval); Py_DECREF(pyCont); + yyfilename = NULL; return NULL; } pyItem = PyDict_New(); @@ -280,5 +292,6 @@ PyObject *clippy_parse(PyObject *self, PyObject *args) } def_yylex_destroy(); fclose(fd); + yyfilename = NULL; return pyCont; } |