Skip to content

Conversation

@hikinggrass
Copy link
Member

When certain malformed messages that during parsing result in a json exceptions are reported to the CSMS it was observed that secondary parsing exceptions can occur when the error message is sent to the CSMS as part of a CallError as well as when the incoming message in re-serialized in the security event to be sent.

This fixes #1104 by catching the secondary exception thrown during error message generation, and by not sending a truncated version of the problematic message but the error message instead.

Describe your changes

Issue ticket number and link

Checklist before requesting a review

  • I have performed a self-review of my code
  • I have made corresponding changes to the documentation
  • If OCPP 2.0.1 or OCPP2.1: I have updated the OCPP 2.x status document
  • I read the contribution documentation and made sure that my changes meet its requirements

When certain malformed messages that during parsing result
in a json exceptions are reported to the CSMS it was observed
that secondary parsing exceptions can occur when the error message
is sent to the CSMS as part of a CallError as well as when the
incoming message in re-serialized in the security event to be sent.

This fixes #1104 by catching the secondary exception thrown during
error message generation, and by not sending a truncated version
of the problematic message but the error message instead.

Signed-off-by: Kai-Uwe Hermann <[email protected]>
Copy link
Contributor

@Pietfried Pietfried left a comment

Choose a reason for hiding this comment

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

lgtm for ocpp2, it looks like we could have similar issues for ocpp1.6. Can you apply these changes to ocpp1.6, too?

@hikinggrass hikinggrass requested a review from Pietfried July 11, 2025 12:35
@hikinggrass hikinggrass merged commit 0b84d7f into main Jul 11, 2025
10 checks passed
@hikinggrass hikinggrass deleted the bugfix/json-exception-during-malformed-message-handling branch July 11, 2025 14:00
stephenredhat pushed a commit to stephenredhat/libocpp that referenced this pull request Aug 11, 2025
…Verest#1107)

* Fix json exceptions being thrown during handling of invalid messages

When certain malformed messages that during parsing result
in a json exceptions are reported to the CSMS it was observed
that secondary parsing exceptions can occur when the error message
is sent to the CSMS as part of a CallError as well as when the
incoming message in re-serialized in the security event to be sent.

This fixes EVerest#1104 by catching the secondary exception thrown during
error message generation, and by not sending a truncated version
of the problematic message but the error message instead.

* Handle json errors in 1.6 message_callback similarly to 2.x code

---------

Signed-off-by: Kai-Uwe Hermann <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invalid JSON in IPC message causes uncaught exception and crash

3 participants