Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 17650: std.getopt range violation when option value is a hyphen #5612

Merged

Conversation

jondegenhardt
Copy link
Contributor

This fixes an issue in std.getopt private function optMatch. This function is used to see if a command line argument represents an option (e.g. "--file", "-a", etc.). It looks at all the arguments on the command line, including option values. (In $ command -f 1 -g 2, "1" and "2" are option values.)

The range violation occurs if an option value is a single hyphen. The optMatch function sees the hyphen and assumes it might be an option argument (like "-f"). It then tests the next character in the string. When the value is a single hyphen the next character does not exist.

A single hyphen (or a single optionChar) only introduces an option, it is never an option by itself. So the easy fix is to also check that the length is at least 2.

Note: Looking through this code it appears there may be other problems like this. I've elected to fix only this case in this PR, as it is the most pressing issue.

@jondegenhardt jondegenhardt requested a review from andralex as a code owner July 15, 2017 20:26
@dlang-bot
Copy link
Contributor

dlang-bot commented Jul 15, 2017

Thanks for your pull request, @jondegenhardt! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.

Some tips to help speed things up:

  • smaller, focused PRs are easier to review than big ones

  • try not to mix up refactoring or style changes with bug fixes or feature enhancements

  • provide helpful commit messages explaining the rationale behind each change

Bear in mind that large or tricky changes may require multiple rounds of review and revision.

Please see CONTRIBUTING.md for more information.

Bugzilla references

Auto-close Bugzilla Description
17650 [REG v2.075.0 b1-b4] std.getopt range violation

Copy link
Member

@andralex andralex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx!

@dlang-bot dlang-bot merged commit 603e406 into dlang:master Jul 15, 2017
@jondegenhardt jondegenhardt deleted the issue-17650-getopt-range-violation branch July 16, 2017 02:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants