lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Sun, 15 Apr 2018 09:57:43 +0200
From:   Ulf Magnusson <ulfalizer@...il.com>
To:     Masahiro Yamada <yamada.masahiro@...ionext.com>
Cc:     Linux Kbuild mailing list <linux-kbuild@...r.kernel.org>,
        Linus Torvalds <torvalds@...ux-foundation.org>,
        Sam Ravnborg <sam@...nborg.org>,
        Nicholas Piggin <npiggin@...il.com>,
        Kees Cook <keescook@...omium.org>,
        Emese Revfy <re.emese@...il.com>, X86 ML <x86@...nel.org>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH 08/30] kconfig: add built-in function support

On Fri, Apr 13, 2018 at 7:06 AM, Masahiro Yamada
<yamada.masahiro@...ionext.com> wrote:
> This commit adds a new concept 'function' to do more text processing
> in Kconfig.
>
> A function call looks like this:
>
>   $(function arg1, arg2, arg3, ...)
>
> This commit adds the basic infrastructure to expand functions.
> Change the text expansion helpers to take arguments.
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@...ionext.com>
> ---
>
> Changes in v3:
>   - Split base infrastructure and 'shell' function
>     into separate patches.
>
> Changes in v2:
>   - Use 'shell' for getting stdout from the comment.
>     It was 'shell-stdout' in the previous version.
>   - Symplify the implementation since the expansion has been moved to
>     lexer.
>
>  scripts/kconfig/preprocess.c | 142 +++++++++++++++++++++++++++++++++++++++----
>  1 file changed, 130 insertions(+), 12 deletions(-)
>
> diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c
> index fa4abc8..e77cf7c 100644
> --- a/scripts/kconfig/preprocess.c
> +++ b/scripts/kconfig/preprocess.c
> @@ -8,6 +8,10 @@
>
>  #include "list.h"
>
> +#define ARRAY_SIZE(arr)                (sizeof(arr) / sizeof((arr)[0]))
> +
> +static char *expand_string_with_args(const char *in, int argc, char *argv[]);
> +
>  /*
>   * Environment variables
>   */
> @@ -74,9 +78,47 @@ void env_write_dep(FILE *f, const char *autoconfig_name)
>         }
>  }
>
> -static char *eval_clause(const char *in)
> +/*
> + * Built-in Functions
> + */
> +struct function {
> +       char *name;
> +       char *(*func)(int argc, char *argv[]);
> +};
> +
> +static const struct function function_table[] = {
> +};
> +
> +static char *function_call(const char *name, int argc, char *argv[])
>  {
> -       char *res, *name;
> +       const struct function *f;
> +       int i;
> +
> +       for (i = 0; i < ARRAY_SIZE(function_table); i++) {
> +               f = &function_table[i];
> +               if (!strcmp(f->name, name))
> +                       return f->func(argc, argv);
> +       }
> +
> +       return NULL;
> +}
> +
> +#define FUNCTION_MAX_ARGS              16
> +
> +/*
> + * Evaluate a clause with arguments.  argc/argv are arguments from the upper
> + * function call.
> + *
> + * Returned string must be freed when done
> + */
> +static char *eval_clause(const char *in, int argc, char *argv[])
> +{
> +       char *tmp, *prev, *p, *res, *name;
> +       char delim = ' ';
> +       int new_argc = 0;
> +       char *new_argv[FUNCTION_MAX_ARGS];
> +       int nest = 0;
> +       int i;
>
>         /*
>          * Returns an empty string because '$()' should be evaluated
> @@ -85,10 +127,73 @@ static char *eval_clause(const char *in)
>         if (!*in)
>                 return xstrdup("");
>
> -       name = expand_string(in);
> +       tmp = xstrdup(in);
> +
> +       prev = p = tmp;
>
> -       res = env_expand(name);
> +       /*
> +        * Split into tokens
> +        * The function name and the first argument are separated by a space.
> +        * Arguments are separated by a comma.
> +        * For example, if the function call is like this:
> +        *   $(foo abc,$(x),$(y))
> +        *
> +        * The input string for this helper should be:
> +        *   foo abc,$(x),$(y)
> +        *
> +        * and split into:
> +        *   new_argv[0]: foo
> +        *   new_argv[1]: abc
> +        *   new_argv[2]: $(x)
> +        *   new_argv[3]: $(y)
> +        */
> +       while (*p) {
> +               if (nest == 0 && *p == delim) {
> +                       *p = 0;
> +                       new_argv[new_argc++] = prev;

Erroring out would be nicer than overflowing the array.

Cheers,
Ulf

Powered by blists - more mailing lists