fix: Unhandled ValueError during authentication#2118
fix: Unhandled ValueError during authentication#2118statxc wants to merge 1 commit intofortra:masterfrom
Conversation
|
Hi @anadrianmanrique. Could you please review my PR and share any feedback? thank you. |
|
Hi @alexisbalbachan @anadrianmanrique . could you please review this PR and share any feedback? |
|
@intelliking this PR it's been tagged already under review. Feedback will be provided as soon the review is completed. |
|
Hi @anadrianmanrique , Please take a look at this PR when you have a moment. If everything looks good, feel free to merge it. thank you |
|
Hi, thanks for this PR. It’s going in the right direction by making the error more descriptive. |
Should I wait? |
|
Hey @alexisbalbachan, have any updates? I opened this PR last month. It’s a simple fix. If there are no further problem, hope to merge this PR 🙏 |
|
Hey @statxc, as mentioned in my previous comment, even though this PR is correct and simple in terms of code it still doesn't solve the issue described in #2099 -> Yes, its message is now more descriptive, but it is still unhandled by smb/smbconnection -> users still get ValueError. The goal of the fix for #2099 is gracefully handling that exception (probably at smb->login()), it should also log the exact reason there, as a debug message) and raising a proper exception for the user (like SessionError stating that the authentication failed). |
… log) When session setup or negotiate response parsing fails (e.g. truncated server response, no NUL in asciiz field), users previously saw an unhandled ValueError: subsection not found. Now: - structure.py: asciiz calcUnpackSize raises descriptive ValueError with field name; pass field through code specifier for 'z=""' format. - smb.py: catch ValueError at all four parse sites (two session-setup paths, negotiate + extended-security), LOG.debug the reason, raise SessionError (STATUS_LOGON_FAILURE for auth, STATUS_INVALID_PARAMETER for negotiate). - smbconnection: docstring notes invalid/truncated server response. - Regression tests: test_structure (asciiz missing NUL, session-like struct), test_smb (mock negotiate + session setup, fromString raises -> SessionError). - IMPLEMENTATION_PLAN_2099.md and ChangeLog entry. Addresses maintainer feedback on PR fortra#2118 (graceful handling + log + SessionError).
Fixes #2099
Problem
When SMB authentication fails due to incomplete server responses (network drops, timeouts), users see:
This error message doesn't indicate what failed or which field caused the issue.
Solution
Added exception handling to catch the ValueError and provide a clearer error message:
Changes
impacket/structure.py: Added try/except block for ASCII string parsing (3 lines)