From 53e1772682d86ed681ce41b4027bd34163023871 Mon Sep 17 00:00:00 2001 From: "Yann E. MORIN" Date: Tue, 13 Aug 2024 12:04:29 +0200 Subject: [PATCH] toolchain/wrapper: check unsafe paths earlier We currently check for unsafe paths right between adding our arguments, and adding the one passed from the command line. This not very consistent. Unsafe paths can only come from the command line, as we are not adding any of our own (hopefully, we know better!), so we can run the check as early as possible. Move the check very early, but not before we handle --help. Signed-off-by: Yann E. MORIN Cc: Romain Naour Cc: Giulio Benetti Cc: Thomas Petazzoni Signed-off-by: Peter Korsgaard --- toolchain/toolchain-wrapper.c | 44 +++++++++++++++++------------------ 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/toolchain/toolchain-wrapper.c b/toolchain/toolchain-wrapper.c index 8b1fb79dde..e644c1e7bb 100644 --- a/toolchain/toolchain-wrapper.c +++ b/toolchain/toolchain-wrapper.c @@ -319,6 +319,28 @@ int main(int argc, char **argv) } } + /* Check for unsafe library and header paths */ + for (i = 1; i < argc; i++) { + const struct str_len_s *opt; + for (opt=unsafe_opts; opt->str; opt++ ) { + /* Skip any non-unsafe option. */ + if (strncmp(argv[i], opt->str, opt->len)) + continue; + + /* Handle both cases: + * - path is a separate argument, + * - path is concatenated with option. + */ + if (argv[i][opt->len] == '\0') { + i++; + if (i == argc) + break; + check_unsafe_path(argv[i-1], argv[i], 0); + } else + check_unsafe_path(argv[i], argv[i] + opt->len, 1); + } + } + #ifdef BR_CCACHE ret = snprintf(ccache_path, sizeof(ccache_path), "%s/bin/ccache", absbasedir); if (ret >= sizeof(ccache_path)) { @@ -475,28 +497,6 @@ int main(int argc, char **argv) #endif } - /* Check for unsafe library and header paths */ - for (i = 1; i < argc; i++) { - const struct str_len_s *opt; - for (opt=unsafe_opts; opt->str; opt++ ) { - /* Skip any non-unsafe option. */ - if (strncmp(argv[i], opt->str, opt->len)) - continue; - - /* Handle both cases: - * - path is a separate argument, - * - path is concatenated with option. - */ - if (argv[i][opt->len] == '\0') { - i++; - if (i == argc) - break; - check_unsafe_path(argv[i-1], argv[i], 0); - } else - check_unsafe_path(argv[i], argv[i] + opt->len, 1); - } - } - /* append forward args */ memcpy(cur, &argv[1], sizeof(char *) * (argc - 1)); cur += argc - 1;