2022-01-31 11:46:03

by Brenda Streiff

[permalink] [raw]
Subject: [PATCH] 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.

Signed-off-by: Brenda Streiff <[email protected]>
---
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(-)

diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c
index 0590f86df6e4..748da578b418 100644
--- a/scripts/kconfig/preprocess.c
+++ b/scripts/kconfig/preprocess.c
@@ -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;
diff --git a/scripts/kconfig/tests/preprocess/builtin_func/Kconfig b/scripts/kconfig/tests/preprocess/builtin_func/Kconfig
index baa328827911..e9791a97f731 100644
--- a/scripts/kconfig/tests/preprocess/builtin_func/Kconfig
+++ b/scripts/kconfig/tests/preprocess/builtin_func/Kconfig
@@ -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'))
diff --git a/scripts/kconfig/tests/preprocess/builtin_func/expected_stdout b/scripts/kconfig/tests/preprocess/builtin_func/expected_stdout
index 82de3a7e97de..8e03e4dfe8f6 100644
--- a/scripts/kconfig/tests/preprocess/builtin_func/expected_stdout
+++ b/scripts/kconfig/tests/preprocess/builtin_func/expected_stdout
@@ -1 +1,2 @@
hello world 0
+hello0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000world
--
2.20.1


2022-02-09 10:23:18

by Masahiro Yamada

[permalink] [raw]
Subject: Re: [PATCH] kconfig: let 'shell' return enough output for deep path names

On Sat, Jan 29, 2022 at 7:02 AM Brenda Streiff <[email protected]> wrote:
>
> 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.
>
> Signed-off-by: Brenda Streiff <[email protected]>

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





> ---
> 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(-)
>
> diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c
> index 0590f86df6e4..748da578b418 100644
> --- a/scripts/kconfig/preprocess.c
> +++ b/scripts/kconfig/preprocess.c
> @@ -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;
> diff --git a/scripts/kconfig/tests/preprocess/builtin_func/Kconfig b/scripts/kconfig/tests/preprocess/builtin_func/Kconfig
> index baa328827911..e9791a97f731 100644
> --- a/scripts/kconfig/tests/preprocess/builtin_func/Kconfig
> +++ b/scripts/kconfig/tests/preprocess/builtin_func/Kconfig
> @@ -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'))
> diff --git a/scripts/kconfig/tests/preprocess/builtin_func/expected_stdout b/scripts/kconfig/tests/preprocess/builtin_func/expected_stdout
> index 82de3a7e97de..8e03e4dfe8f6 100644
> --- a/scripts/kconfig/tests/preprocess/builtin_func/expected_stdout
> +++ b/scripts/kconfig/tests/preprocess/builtin_func/expected_stdout
> @@ -1 +1,2 @@
> hello world 0
> +hello0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000world
> --
> 2.20.1
>


--
Best Regards
Masahiro Yamada