Fix uninitialized memory access dependent on argc

It seems that `parse_cmd_opts` does not correctly handle no arguments,
and so argc was being decremented to -1 causing uninitialized memory
access when argv[0] was dereferenced at a later point.
This commit is contained in:
Mahmoud Al-Qudsi 2017-10-11 07:22:42 +02:00
parent 98eceba124
commit 639faf1c7f

View file

@ -405,8 +405,10 @@ int builtin_read(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
int optind;
int retval = parse_cmd_opts(opts, &optind, argc, argv, parser, streams);
if (retval != STATUS_CMD_OK) return retval;
if (!opts.stdout) {
argc -= optind;
argv += optind;
}
if (opts.print_help) {
builtin_print_help(parser, streams, cmd, streams.out);