From 2663ba8f0d436f1a2f274668d2d06462049f4ac3 Mon Sep 17 00:00:00 2001 From: gaochao Date: Wed, 30 Nov 2022 15:30:09 +0800 Subject: [PATCH] kconfig: fix whitelist check when KBUILD_OUTPUT is specified ohos inclusion category: bugfix issue: I63X9J CVE: NA Signed-off-by: gaochao --------------------------------------- if KBUILD_OUTPUT is specified, get fullpath with SRCTREE --- scripts/kconfig/parser.y | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y index 421bb2fa6e51..46b4ccea7c0a 100644 --- a/scripts/kconfig/parser.y +++ b/scripts/kconfig/parser.y @@ -5,6 +5,7 @@ %{ #include +#include #include #include #include @@ -24,7 +25,6 @@ int cdebug = PRINTD; static const char *kconfig_white_list[] = { "vendor/Kconfig", "net/newip/Kconfig", - "net/newip/hooks/Kconfig", }; static void yyerror(const char *err); @@ -33,6 +33,7 @@ static void zconf_error(const char *err, ...); static bool zconf_endtoken(const char *tokenname, const char *expected_tokenname); static bool zconf_in_whitelist(const char *path); +static bool zconf_access_file(const char *name); struct symbol *symbol_hash[SYMBOL_HASHSIZE]; @@ -375,7 +376,7 @@ menu_option_list: source_stmt: T_SOURCE T_WORD_QUOTE T_EOL { printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2); - if (access(($2), F_OK) == 0 || zconf_in_whitelist($2) == false) { + if (zconf_access_file($2) == true || zconf_in_whitelist($2) == false) { zconf_nextfile($2); } free($2); @@ -494,6 +495,29 @@ assign_val: %% +static bool zconf_access_file(const char *name) +{ + char *env = NULL; + char fullname[PATH_MAX+1]; + + if (access(name, F_OK) == 0) { + return true; + } + + if (name != NULL && name[0] != '/') { + env = getenv(SRCTREE); + if (env) { + snprintf(fullname, sizeof(fullname), + "%s/%s", env, name); + if (access(fullname, F_OK) == 0) { + return true; + } + } + } + + return false; +} + static bool zconf_in_whitelist(const char *path) { int i; -- Gitee