Print usage and exit when -N used with invalid IP. #2227
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue type
Defect/Feature description
The command-line argument supplied with the -N option is supposed to be an IP address for filtering purposes, and is passed to inet_pton() to be validated. However, the return value from inet_pton() is not checked properly; it will be zero if input string is invalid, but radwho only checks for a negative value. (The return will never be negative in this case, because the address family AF_INET parameter is always valid.)
How to reproduce issue
radwho -N foo
Should output help/usage text and exit, but instead proceeds to look for radutmp file.
Commit message from pull request
Check for all possible error return values from inet_pton(),
particularly zero, as this indicates an invalid IP address was
passed in the input string, whereas -1 is returned only when the
address family parameter is invalid, which is never the case
here because it's always AF_INET.