diff options
author | Andrew Kaster <andrewdkaster@gmail.com> | 2021-05-14 23:42:13 -0600 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-05-16 21:58:14 +0100 |
commit | b9d65da5c89a2bd42e6108d9bf8eab14b5f19566 (patch) | |
tree | aaf3794c3e14230c4bc02365f4530836727c4eac /Userland/Libraries/LibCore | |
parent | 11214bc94d3a327ff92192b46b2fe79313044914 (diff) | |
download | serenity-b9d65da5c89a2bd42e6108d9bf8eab14b5f19566.zip |
LibCore: Use Vector instead of VLA in ArgsParser::parse()
If there happens to be zero positional arguments, this constructs a
0-length VLA, which is UB caught by UBSAN.
Diffstat (limited to 'Userland/Libraries/LibCore')
-rw-r--r-- | Userland/Libraries/LibCore/ArgsParser.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/Userland/Libraries/LibCore/ArgsParser.cpp b/Userland/Libraries/LibCore/ArgsParser.cpp index c942c60695..56fa4df5c6 100644 --- a/Userland/Libraries/LibCore/ArgsParser.cpp +++ b/Userland/Libraries/LibCore/ArgsParser.cpp @@ -106,7 +106,8 @@ bool ArgsParser::parse(int argc, char** argv, bool exit_on_failure) // We're done processing options, now let's parse positional arguments. int values_left = argc - optind; - int num_values_for_arg[m_positional_args.size()]; + Vector<int, 16> num_values_for_arg; + num_values_for_arg.resize(m_positional_args.size(), true); int total_values_required = 0; for (size_t i = 0; i < m_positional_args.size(); i++) { auto& arg = m_positional_args[i]; |