Skip to contentSkip to conversation

kconfig: let 'shell' return enough output for deep path names

PATCH In review Brenda Streiff 2 participants 2 messages Jan 28, 2022 – Feb 7, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kconfig: let 'shell' return enough output for deep path names

The 'shell' built-in only returns the first 256 bytes of the command's output. In some cases, 'shell' is used to return a path; by bumping up the buffer size to 4096 this lets us capture up to PATH_MAX.

The specific case where I ran into this was due to commit 1e860048c53e ("gcc-plugins: simplify GCC plugin-dev capability test"). After this change, we now use $(shell,$(CC) -print-file-name=plugin) to return a path; if the gcc path is particularly long, then the path ends up truncated at the 256 byte mark, which makes the HAVE_GCC_PLUGINS depends test always fail.

---
 scripts/kconfig/preprocess.c                                  | 2 +-
 scripts/kconfig/tests/preprocess/builtin_func/Kconfig         | 3 +++
 scripts/kconfig/tests/preprocess/builtin_func/expected_stdout | 1 +
 3 files changed, 5 insertions(+), 1 deletion(-)
scripts/kconfig/preprocess.c +1 -1
index 0590f86df6e4..748da578b418 100644
@@ -141,7 +141,7 @@ static char *do_lineno(int argc, char *argv[])
 static char *do_shell(int argc, char *argv[])
 {
 	FILE *p;
-	char buf[256];
+	char buf[4096];
 	char *cmd;
 	size_t nread;
 	int i;
scripts/kconfig/tests/preprocess/builtin_func/Kconfig +3 -0
index baa328827911..e9791a97f731 100644
@@ -25,3 +25,6 @@ $(warning,$(shell,printf 'hello\nworld\n\n4\n\n\n'))
 # 'lineno' to the line number.
 $(warning,filename=$(filename))
 $(warning,lineno=$(lineno))
+
+# 'shell' can return more than 256 bytes of output
+$(info,$(shell,printf 'hello%01024dworld\n' '0'))
scripts/kconfig/tests/preprocess/builtin_func/expected_stdout +1 -0
index 82de3a7e97de..8e03e4dfe8f6 100644
@@ -1 +1,2 @@
 hello world 0
+hello0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000world
Signature · 1 line
2.20.1
#1 lore raw
Quoted 5 lines · Brenda Streiff

The 'shell' built-in only returns the first 256 bytes of the command's output. In some cases, 'shell' is used to return a path; by bumping up the buffer size to 4096 this lets us capture up to PATH_MAX.

Quoted 8 lines

The specific case where I ran into this was due to commit 1e860048c53e ("gcc-plugins: simplify GCC plugin-dev capability test"). After this change, we now use $(shell,$(CC) -print-file-name=plugin) to return a path; if the gcc path is particularly long, then the path ends up truncated at the 256 byte mark, which makes the HAVE_GCC_PLUGINS depends test always fail.

Thanks, applied to linux-kbuild,
(but I dropped the change to tests)

Quoted 40 lines
---
 scripts/kconfig/preprocess.c                                  | 2 +-
 scripts/kconfig/tests/preprocess/builtin_func/Kconfig         | 3 +++
 scripts/kconfig/tests/preprocess/builtin_func/expected_stdout | 1 +
 3 files changed, 5 insertions(+), 1 deletion(-)
scripts/kconfig/preprocess.c +1 -1
index 0590f86df6e4..748da578b418 100644
@@ -141,7 +141,7 @@ static char *do_lineno(int argc, char *argv[])
 static char *do_shell(int argc, char *argv[])
 {
        FILE *p;
-       char buf[256];
+       char buf[4096];
        char *cmd;
        size_t nread;
        int i;
scripts/kconfig/tests/preprocess/builtin_func/Kconfig +3 -0
index baa328827911..e9791a97f731 100644
@@ -25,3 +25,6 @@ $(warning,$(shell,printf 'hello\nworld\n\n4\n\n\n'))
 # 'lineno' to the line number.
 $(warning,filename=$(filename))
 $(warning,lineno=$(lineno))
+
+# 'shell' can return more than 256 bytes of output
+$(info,$(shell,printf 'hello%01024dworld\n' '0'))
scripts/kconfig/tests/preprocess/builtin_func/expected_stdout +1 -1
index 82de3a7e97de..8e03e4dfe8f6 100644
@@ -1 +1,2 @@
 hello world 0
+hello0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000world
--

2.20.1

Signature · 2 lines
Best Regards
Masahiro Yamada