Validate argv entries before std::string construction in ParseCLI#173
Validate argv entries before std::string construction in ParseCLI#173jmestwa-coder wants to merge 1 commit into
Conversation
|
In what case would |
|
If anything at all, this should be some kind of debug assert, but I don't think even that. argc and argv conventions are well known, and there are so many ways that the understanding can be abused. Bad argc value, null pointers, dangling pointers, pointers to non-char data. We shouldn't protect against error conditions that literally no program will ever hit. |
|
@Taywee. My intent here was specifically to avoid the std::string(nullptr) UB path for malformed caller-constructed argv arrays, but I understand and respect the project's position that these states are considered caller responsibility rather than something the library should validate internally. |
Summary
ParseCLI(argc, argv)previously bulk-constructedstd::stringobjects directly from the suppliedargvrange.If an interior
argventry isnullptr, this results in construction ofstd::string(nullptr), which is undefined behavior and can crash depending on the standard library implementation.This change validates each argument pointer before string construction and converts malformed input containing null entries into a deterministic parse failure.
Changes
args.assign(argv + 1, argv + argc)construction with per-entry validationnullptrentries beforestd::stringconstructionError::ParseinARGS_NOEXCEPTbuildsParseErrorin normal buildsargvinputsTests
Added regression coverage for:
argvcontaining interior null entriesARGS_NOEXCEPTbehavior