Skip to content

Reject negative length and offset values in DatagramPacket#696

Merged
swebb2066 merged 1 commit into
apache:masterfrom
jmestwa-coder:validate-datagrampacket
Jun 11, 2026
Merged

Reject negative length and offset values in DatagramPacket#696
swebb2066 merged 1 commit into
apache:masterfrom
jmestwa-coder:validate-datagrampacket

Conversation

@jmestwa-coder

Copy link
Copy Markdown
Contributor

Summary

Reject negative length and offset values when creating or modifying DatagramPacket instances.

Changes

  • Add centralized validation for DatagramPacket length and offset arguments.
  • Reject negative length values in all constructors and mutators.
  • Reject negative offset values in all constructors and mutators.
  • Prevent invalid packet state from being stored and propagated.
  • Add regression tests covering negative constructor and mutation inputs.
  • Register the new test target in the helper test suite.

Rationale

DatagramPacket currently accepts negative length and offset values and stores them unchanged. This change enforces basic argument invariants at the DatagramPacket boundary and ensures invalid values are rejected before they can propagate through socket operations.

Testing

  • Added constructor validation tests for negative length and offset values.
  • Added mutation validation tests for negative setLength() and setData() inputs.
  • Verified focused regression coverage for all supported negative-input paths.

@swebb2066

Copy link
Copy Markdown
Contributor

I would like to change the interface in the next ABI version to use size_t instead of int.

The test case would then be unnecessary.

Would you like to introduce the interface changes for the next ABI in this PR?

@jmestwa-coder

Copy link
Copy Markdown
Contributor Author

Using size_t for the length and offset parameters does seem like a cleaner way to enforce the invariant at the API level.

I'm happy to rework the PR around the interface change if that's the preferred direction. Is there a specific branch or upcoming ABI version where you would like these changes to target?

@rm5248

rm5248 commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

master branch is fine, you need to use the LOG4CXX_ABI_VERSION macro

@jmestwa-coder jmestwa-coder force-pushed the validate-datagrampacket branch from 10a436c to 4e08a6c Compare June 10, 2026 16:08
@swebb2066 swebb2066 merged commit eebcb0a into apache:master Jun 11, 2026
17 checks passed
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.

3 participants