diff mbox series

[v2,05/21] kconfig: remove string expansion in file_lookup()

Message ID 1522128575-5326-6-git-send-email-yamada.masahiro@socionext.com
State New
Headers show
Series kconfig: move compiler capability tests to Kconfig | expand

Commit Message

Masahiro Yamada March 27, 2018, 5:29 a.m. UTC
There are two callers of file_lookup().

[1] zconf_initscan()
    This is used to open the first Kconfig.  However, it cannot
    contain environments in the file path because zconf_fopen() is
    called before file_lookup().  By swapping the call order,
    KBUILD_KCONFIG would be able to contain environments, but I do
    not see practical benefits to support it.

[2] zconf_nextfile()
    This is used to open the next file from 'source' statement like
        source "arch/$SRCARCH/Kconfig"
    but this has already been expanded in the lexer phase.

So, file_lookup() does not need to expand the given path.

By the way, file_lookup() was already buggy; it expanded a given path,
but it used the path before expansion for look-up:
        if (!strcmp(name, file->name)) {

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

---

Changes in v2:
  - Simplify the patch.  Just remove text expansion.

 scripts/kconfig/util.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

-- 
2.7.4

Comments

Kees Cook March 28, 2018, 3:34 a.m. UTC | #1
On Mon, Mar 26, 2018 at 10:29 PM, Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:
> There are two callers of file_lookup().

>

> [1] zconf_initscan()

>     This is used to open the first Kconfig.  However, it cannot

>     contain environments in the file path because zconf_fopen() is

>     called before file_lookup().  By swapping the call order,

>     KBUILD_KCONFIG would be able to contain environments, but I do

>     not see practical benefits to support it.

>

> [2] zconf_nextfile()

>     This is used to open the next file from 'source' statement like

>         source "arch/$SRCARCH/Kconfig"

>     but this has already been expanded in the lexer phase.

>

> So, file_lookup() does not need to expand the given path.

>

> By the way, file_lookup() was already buggy; it expanded a given path,

> but it used the path before expansion for look-up:

>         if (!strcmp(name, file->name)) {

>

> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>


Reviewed-by: Kees Cook <keescook@chromium.org>


-Kees

-- 
Kees Cook
Pixel Security
Ulf Magnusson April 1, 2018, 2:52 a.m. UTC | #2
On Tue, Mar 27, 2018 at 7:29 AM, Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:
> There are two callers of file_lookup().

>

> [1] zconf_initscan()

>     This is used to open the first Kconfig.  However, it cannot

>     contain environments in the file path because zconf_fopen() is

>     called before file_lookup().  By swapping the call order,

>     KBUILD_KCONFIG would be able to contain environments, but I do

>     not see practical benefits to support it.

>

> [2] zconf_nextfile()

>     This is used to open the next file from 'source' statement like

>         source "arch/$SRCARCH/Kconfig"

>     but this has already been expanded in the lexer phase.

>

> So, file_lookup() does not need to expand the given path.

>

> By the way, file_lookup() was already buggy; it expanded a given path,

> but it used the path before expansion for look-up:

>         if (!strcmp(name, file->name)) {

>

> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>


s/environments/environment variables/

Reviewed-by: Ulf Magnusson <ulfalizer@gmail.com>
diff mbox series

Patch

diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c
index 136e497..3d27c49 100644
--- a/scripts/kconfig/util.c
+++ b/scripts/kconfig/util.c
@@ -58,18 +58,16 @@  char *expand_string_value(const char *in)
 struct file *file_lookup(const char *name)
 {
 	struct file *file;
-	char *file_name = expand_string_value(name);
 
 	for (file = file_list; file; file = file->next) {
 		if (!strcmp(name, file->name)) {
-			free(file_name);
 			return file;
 		}
 	}
 
 	file = xmalloc(sizeof(*file));
 	memset(file, 0, sizeof(*file));
-	file->name = file_name;
+	file->name = xstrdup(name);
 	file->next = file_list;
 	file_list = file;
 	return file;