Fix salt-ssh UnicodeError crash on long -E/--pcre targets in is_reachable_host#69757
Open
ggiesen wants to merge 1 commit into
Open
Fix salt-ssh UnicodeError crash on long -E/--pcre targets in is_reachable_host#69757ggiesen wants to merge 1 commit into
ggiesen wants to merge 1 commit into
Conversation
salt.utils.network.is_reachable_host only caught socket.gaierror, but socket.getaddrinfo raises UnicodeError (an idna "label too long" error, which is not a subclass of gaierror) when a name contains a DNS label longer than 63 characters. A long salt-ssh -E/--pcre target triggers this, so _expand_target crashed instead of treating the target as not a reachable host. Also catch UnicodeError and return False. Fixes saltstack#57207
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What does this PR do?
salt.utils.network.is_reachable_host()only caughtsocket.gaierror, butsocket.getaddrinfo()raisesUnicodeError("encoding with 'idna' codec failed (label too long)") -- which is NOT a subclass ofsocket.gaierror-- when a name contains a DNS label longer than 63 characters. This PR also catchesUnicodeErrorand returnsFalse, so an overlong name is reported as "not a reachable host" instead of raising.What issues does this PR fix or reference?
Fixes #57207
Previous Behavior
Running salt-ssh with a long PCRE target crashed with an unhandled traceback:
The
-E/--pcretarget has no dots, so the whole regex is one IDNA label; when it exceeds 63 charactersgetaddrinforaisesUnicodeErrorduring IDNA encoding, before any network lookup.is_reachable_hostdid not catch it, so it propagated out of_expand_targetand aborted salt-ssh.New Behavior
is_reachable_hostcatchesUnicodeErrorin addition tosocket.gaierrorand returnsFalsefor such names. A PCRE target is correctly treated as not a reachable host, so_expand_targetproceeds normally and salt-ssh no longer crashes. The existingsocket.gaierrorpath and successful-resolution path are unchanged.Merge requirements satisfied?
changelog/57207.fixed.mdtests/pytests/unit/utils/test_network.py:test_is_reachable_host_57207: production-exact reproduction using the verbatim issue target; realgetaddrinforaisesUnicodeErrordeterministically (69-char label, no network) and the function must returnFalse. Fails without the fix, passes with it.test_is_reachable_host_gaierror_unchanged: must-not-regress -- the pre-existingsocket.gaierrorpath still returnsFalse(passes with and without the fix).test_is_reachable_host_resolvable_returns_true: peripheral coverage of the success branch (a resolvable name still returnsTrue), guarding against the broadened except swallowing a good lookup.Commits signed with GPG?
No