[Tarantool-patches] [PATCH 1/1] app: handle concatenated argv name-value correctly
Igor Munkin
imun at tarantool.org
Wed Feb 19 11:54:10 MSK 2020
Vlad,
Thanks for the patch it LGTM.
However, the Travis job failed on the newly added test[1]. It looks like
the wait underneath the pclose has failed. I can't reproduce the problem
on my machine, but I guess the strace output for the failed child:close
might shed some light on the issue. Nevertheless, what do you think
regarding omitting the close call since the resourses will be
automatically released considering the doc[2]?
On 19.02.20, Vladislav Shpilevoy wrote:
> The server used to crash when any option argument was passed with
> a value concatenated to it, like this: '-lvalue', '-evalue'
> instead of '-l value' and '-e value'.
>
> However this is a valid way of writing values, and it should not
> have crashed regardless of its validity.
>
> The bug was in usage of 'optind' global variable from getopt()
> function family. It is not supposed to be used for getting an
> option's value. It points to a next argv to parse. Next argv !=
> value of current argv, like it was with '-lvalue' and '-evalue'.
>
> For getting a current value there is a variable 'optarg'.
>
> Closes #4775
> ---
> Branch: https://github.com/tarantool/tarantool/tree/gerold103/gh-4775-crash-on-l-e-opts
> Issue: https://github.com/tarantool/tarantool/issues/4775
>
> @ChangeLog
> - Fixed crash at attempt to use -e and -l command line options
> concatenated with their values, like this: -eprint(100)
> (gh-4775).
>
> src/lua/init.c | 4 ++--
> src/lua/init.h | 2 +-
> src/main.cc | 13 +++++--------
> test/app/gh-4775-crash-args-l-e.result | 15 +++++++++++++++
> test/app/gh-4775-crash-args-l-e.test.lua | 6 ++++++
> 5 files changed, 29 insertions(+), 11 deletions(-)
> create mode 100644 test/app/gh-4775-crash-args-l-e.result
> create mode 100644 test/app/gh-4775-crash-args-l-e.test.lua
>
> diff --git a/test/app/gh-4775-crash-args-l-e.result b/test/app/gh-4775-crash-args-l-e.result
> new file mode 100644
> index 000000000..eff1ee763
> --- /dev/null
> +++ b/test/app/gh-4775-crash-args-l-e.result
> @@ -0,0 +1,15 @@
> +-- test-run result file version 2
> +--
> +-- gh-4775: crash on option concatenated with value.
> +--
> +child = io.popen('tarantool -e"print(100) os.exit()"')
> + | ---
> + | ...
> +child:read()
> + | ---
> + | - '100'
> + | ...
> +child:close()
> + | ---
> + | - true
> + | ...
> diff --git a/test/app/gh-4775-crash-args-l-e.test.lua b/test/app/gh-4775-crash-args-l-e.test.lua
> new file mode 100644
> index 000000000..1cccb78a4
> --- /dev/null
> +++ b/test/app/gh-4775-crash-args-l-e.test.lua
> @@ -0,0 +1,6 @@
> +--
> +-- gh-4775: crash on option concatenated with value.
> +--
> +child = io.popen('tarantool -e"print(100) os.exit()"')
> +child:read()
> +child:close()
> --
> 2.21.1 (Apple Git-122.3)
>
[1]: https://travis-ci.org/tarantool/tarantool/jobs/652226987#L4873
[2]: https://www.lua.org/manual/5.1/manual.html#pdf-file:close
--
Best regards,
IM
More information about the Tarantool-patches
mailing list