Skip to content

Commit

Permalink
[#2788] reset optarg
Browse files Browse the repository at this point in the history
optarg is not reset in musl's getopt and it leaks values to other flags.
Reset it for all systems because it cannot hurt. If you remove the
optarg reset, you should see the bug in action on alpine systems in
DstubControllerTest.commandLineArgs when parsing argv2:
```
[ RUN      ] DStubControllerTest.commandLineArgs
d_controller_unittests.cc:102: Failure
Expected equality of these values:
  std::string(ex.what())
    Which is: "unsupported option: -b cfgName"
  "unsupported option: -b"
[  FAILED  ] DStubControllerTest.commandLineArgs (14 ms)
```
  • Loading branch information
andrei-pavel committed Jan 26, 2024
1 parent 697e9fa commit c3507eb
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/lib/process/d_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ DControllerBase::parseArgs(int argc, char* argv[]) {
// ("c" or "d") handle it here. If its a valid custom option, then
// invoke customOption.
int ch;
optarg = 0;
opterr = 0;
optind = 1;
std::string opts("dvVWc:t:" + getCustomOpts());
Expand Down

0 comments on commit c3507eb

Please sign in to comment.