mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Fix options parsing segfault
A command like this would segfault: zeek -b test.zeek --debug The issue was that `getopt_long` was using a null element to determine what the end of the options array is. If it saw a non-null element after `--debug` it would say it's the argument for optarg, even if it's beyond `zeek_args.size()`. Instead, just make sure the array is null-terminated.
This commit is contained in:
parent
cb44a6ca53
commit
30ccee263e
1 changed files with 7 additions and 1 deletions
|
@ -424,11 +424,17 @@ Options parse_cmdline(int argc, char** argv) {
|
|||
opterr = 0;
|
||||
|
||||
// getopt may permute the array, so need yet another array
|
||||
auto zargs = std::make_unique<char*[]>(zeek_args.size());
|
||||
//
|
||||
// Make sure this array is one greater than zeek_args and ends in nullptr, otherwise
|
||||
// getopt may go beyond the end of the array
|
||||
auto zargs = std::make_unique<char*[]>(zeek_args.size() + 1);
|
||||
|
||||
for ( size_t i = 0; i < zeek_args.size(); ++i )
|
||||
zargs[i] = zeek_args[i].data();
|
||||
|
||||
// Make sure getopt doesn't go past the end
|
||||
zargs[zeek_args.size()] = nullptr;
|
||||
|
||||
while ( (op = getopt_long(zeek_args.size(), zargs.get(), opts, long_opts, &long_optsind)) != EOF )
|
||||
switch ( op ) {
|
||||
case 'a': rval.parse_only = true; break;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue