]> git.ipfire.org Git - thirdparty/coreutils.git/commit
env: simplify --split-string memory management
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 30 Mar 2021 04:42:44 +0000 (21:42 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 30 Mar 2021 04:44:58 +0000 (21:44 -0700)
commite3766c5db176ca7abbb8212d5b0b7862fb98a5be
treedf17e7a75d6c05e19ba780e8f12e2e6d038aa28c
parent5b5622f6056d428820cf9c24b00b42516cbda6d1
env: simplify --split-string memory management

* bootstrap.conf (gnulib_modules): Add idx.
* src/env.c: Include idx.h, minmax.h.
Prefer idx_t to ptrdiff_t when values are nonnegative.
(valid_escape_sequence, escape_char, validate_split_str)
(CHECK_START_NEW_ARG):
Remove; no longer needed now that we validate as we go.
(struct splitbuf): New type.
(splitbuf_grow, splitbuf_append_byte, check_start_new_arg)
(splitbuf_finishup): New functions.
(build_argv): New arg ARGC.  Validate and process in one go, using
the new functions; this is simpler and more reliable than the old
approach (as witness the recent bug).  Avoid integer overflow in
the unlikely case where the string contains more than INT_MAX
arguments.
(parse_split_string): Simplify by exploiting the new build_argv.
bootstrap.conf
src/env.c