From e59b7670736c2942164406f32755b6f25f9f1814 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Sat, 21 Jun 2008 22:25:39 +0000 Subject: [PATCH] Report errors upon malformed include directives --- src/cpp.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/cpp.c b/src/cpp.c index f50b930..25879ac 100644 --- a/src/cpp.c +++ b/src/cpp.c @@ -625,11 +625,14 @@ static int _directive_include(Cpp * cpp, Token * token, char const * str) if((path = _include_path(cpp, token, str)) == NULL && (path = _include_path(cpp->parent, token, str)) == NULL) + { + token_set_code(token, CPP_CODE_META_ERROR); + token_set_string(token, error_get()); return 0; + } token_set_code(token, CPP_CODE_META_INCLUDE); if((cpp->subparser = cpp_new(path, cpp->filters)) == NULL) { - error_set_code(-1, "%s: %s", path, strerror(errno)); free(path); return -1; } @@ -654,12 +657,21 @@ static char * _include_path(Cpp * cpp, Token * token, char const * str) else if(str[0] == '<') d = '>'; else + { + error_set("%s", "Invalid include directive"); return NULL; + } len = strlen(str); if(len < 3 || str[len - 1] != d) + { + error_set("%s", "Invalid include directive"); return NULL; + } if((path = strdup(&str[1])) == NULL) + { + error_set("%s", strerror(errno)); return NULL; + } path[len - 2] = '\0'; p = _path_lookup(cpp, token, path, d == '>'); free(path);