[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAFd5g47VmNtGv6=GS94QHY0+GW8yLFRLnS4F+ieo2Sh3suB-sQ@mail.gmail.com>
Date: Thu, 4 Feb 2021 11:52:18 -0800
From: Brendan Higgins <brendanhiggins@...gle.com>
To: Daniel Latypov <dlatypov@...gle.com>
Cc: David Gow <davidgow@...gle.com>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
"open list:KERNEL SELFTEST FRAMEWORK"
<linux-kselftest@...r.kernel.org>,
Shuah Khan <skhan@...uxfoundation.org>
Subject: Re: [PATCH v2 3/3] kunit: tool: fix unintentional statefulness in run_kernel()
On Thu, Feb 4, 2021 at 9:31 AM Daniel Latypov <dlatypov@...gle.com> wrote:
>
> This is a bug that has been present since the first version of this
> code.
> Using [] as a default parameter is dangerous, since it's mutable.
>
> Example using the REPL:
> >>> def bad(param = []):
> ... param.append(len(param))
> ... print(param)
> ...
> >>> bad()
> [0]
> >>> bad()
> [0, 1]
>
> This wasn't a concern in the past since it would just keep appending the
> same values to it.
>
> E.g. before, `args` would just grow in size like:
> [mem=1G', 'console=tty']
> [mem=1G', 'console=tty', mem=1G', 'console=tty']
>
> But with now filter_glob, this is more dangerous, e.g.
> run_kernel(filter_glob='my-test*') # default modified here
> run_kernel() # filter_glob still applies here!
> That earlier `filter_glob` will affect all subsequent calls that don't
> specify `args`.
>
> Note: currently the kunit tool only calls run_kernel() at most once, so
> it's not possible to trigger any negative side-effects right now.
>
> Fixes: 6ebf5866f2e8 ("kunit: tool: add Python wrappers for running KUnit tests")
> Signed-off-by: Daniel Latypov <dlatypov@...gle.com>
Whoah, nice catch! I didn't even know that was a thing!
Reviewed-by: Brendan Higgins <brendanhiggins@...gle.com>
Powered by blists - more mailing lists