Skip to content

Reject negative length and offset values in DatagramPacket#696

Open
jmestwa-coder wants to merge 1 commit into
apache:masterfrom
jmestwa-coder:validate-datagrampacket
Open

Reject negative length and offset values in DatagramPacket#696
jmestwa-coder wants to merge 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?

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.

2 participants