Skip to content

fix: prevent Poco::InvalidArgumentException crash in peer module#491

Merged
lanthora merged 1 commit intomasterfrom
fix/peer-invalid-arg-exception
Feb 25, 2026
Merged

fix: prevent Poco::InvalidArgumentException crash in peer module#491
lanthora merged 1 commit intomasterfrom
fix/peer-invalid-arg-exception

Conversation

@lanthora
Copy link
Owner

This commit fixes a critical crash caused by unhandled Poco::InvalidArgumentException when processing peer messages with invalid IP addresses or ports.

Changes:

  1. Added exception handling in Peer::handlePubInfo (peer/peer.cc)

    • Catch Poco::Exception when constructing SocketAddress
    • Log detailed error information (IP, port, error message)
    • Return early to prevent invalid state propagation
  2. Added exception handling in PeerManager::handlePubInfo (peer/manager.cc)

    • Wrap peer map operations in try-catch
    • Catch both Poco::Exception and std::exception
    • Log source peer IP and detailed error context
  3. Added exception handling in PeerManager::handlePeerQueue (peer/manager.cc)

    • Wrap entire message handling switch in try-catch
    • Log message type and error information
    • Return 0 to continue processing instead of crashing
  4. Fixed websocket close frame logging (websocket/client.cc)

    • Changed from direct buffer output to hex format
    • Prevents systemd journalctl from showing "blob data"

Root Cause:
When receiving network messages with invalid IP addresses (e.g., all zeros), Poco::Net::SocketAddress constructor throws Poco::InvalidArgumentException. This exception was uncaught in the message processing thread, causing std::terminate() to be called and the program to crash.

Impact:

  • Prevents crash when processing invalid peer messages
  • Provides detailed error logging for debugging
  • Allows program to continue running instead of terminating

Tested: Compiles successfully with no warnings

@lanthora lanthora force-pushed the fix/peer-invalid-arg-exception branch from 2efdfc1 to 3422bff Compare February 25, 2026 11:47
This commit fixes a critical crash caused by unhandled Poco::InvalidArgumentException
when processing peer messages with invalid IP addresses or ports.

Changes:
1. Added exception handling in Peer::handlePubInfo (peer/peer.cc)
   - Catch Poco::Exception when constructing SocketAddress
   - Log detailed error information (IP, port, error message)
   - Return early to prevent invalid state propagation

2. Added exception handling in PeerManager::handlePubInfo (peer/manager.cc)
   - Wrap peer map operations in try-catch
   - Catch both Poco::Exception and std::exception
   - Log source peer IP and detailed error context

3. Added exception handling in PeerManager::handlePeerQueue (peer/manager.cc)
   - Wrap entire message handling switch in try-catch
   - Log message type and error information
   - Return 0 to continue processing instead of crashing

4. Fixed websocket close frame logging (websocket/client.cc)
   - Changed from direct buffer output to hex format
   - Prevents systemd journalctl from showing "blob data"

5. Bumped version to 6.1.7

Root Cause:
When receiving network messages with invalid IP addresses (e.g., all zeros),
Poco::Net::SocketAddress constructor throws Poco::InvalidArgumentException.
This exception was uncaught in the message processing thread, causing std::terminate()
to be called and the program to crash.

Impact:
- Prevents crash when processing invalid peer messages
- Provides detailed error logging for debugging
- Allows program to continue running instead of terminating
- Version: 6.1.7

Tested: Compiles successfully with no warnings
@lanthora lanthora force-pushed the fix/peer-invalid-arg-exception branch from 3422bff to ef58449 Compare February 25, 2026 11:48
@lanthora lanthora merged commit 7e3f1ac into master Feb 25, 2026
4 checks passed
@lanthora lanthora deleted the fix/peer-invalid-arg-exception branch February 25, 2026 11:51
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