Skip to content

tests: handle missing --max-level argument - #349

Open
1234binpig wants to merge 1 commit into
yaml:masterfrom
1234binpig:fix-max-level-missing-argument
Open

1234binpig wants to merge 1 commit into
yaml:masterfrom
1234binpig:fix-max-level-missing-argument

Conversation

@1234binpig

Copy link
Copy Markdown

Problem

run-parser and run-parser-test-suite assume that --max-level is always followed by a value.

When the option is the final command-line argument, both programs increment the argument index past the end of argv and pass argv[argc] to strtol().

Fix

Check that a value follows --max-level before consuming the next argument.

If the value is missing, print usage information and exit with a nonzero status.

Testing

Verified that:

  • run-parser --max-level exits with status 1;
  • run-parser-test-suite --max-level exits with status 1;
  • valid --max-level 100 usage still succeeds in both tools;
  • git diff --check passes.

Both run-parser and run-parser-test-suite incremented the argument
index after --max-level without first checking that a value followed.

When --max-level was the final argument, this caused argv[argc] to be
passed to strtol().

Reject a missing value and exit with an error instead.

Signed-off-by: huangwenbin <huangwenbin@kylinos.cn>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant