Skip to content

Check valid parent selection hash string#12985

Open
serrislew wants to merge 2 commits intoapache:masterfrom
serrislew:parent_hash
Open

Check valid parent selection hash string#12985
serrislew wants to merge 2 commits intoapache:masterfrom
serrislew:parent_hash

Conversation

@serrislew
Copy link
Contributor

Resolves #12973 by checking parent hash string length

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses a reported memory-safety issue in ATS parent selection parsing by adding validation for the optional &hash portion of parent entries, preventing oversized hash strings from being copied into fixed-size buffers.

Changes:

  • Add a length check for the optional parent &hash string during ParentRecord::ProcessParents() parsing.
  • Fail parsing with a specific error when the hash string exceeds the allowed maximum.

Comment on lines +559 to +561
if (tmp3 && strlen(tmp3) > MAXDNAME) {
errPtr = "Parent hash_string is too long";
goto MERROR;
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

The new length guard is off by one because tmp3 points at the '&' separator while the destination buffer is hash_string[MAXDNAME + 1] and the copy size is strlen(tmp3) (which includes the '&'). As written, a hash string of exactly MAXDNAME bytes (valid for MAXDNAME + 1 buffer including NUL) is rejected. Consider validating against strlen(tmp3) > MAXDNAME + 1 (copy size) or checking strlen(tmp3 + 1) > MAXDNAME (hash-string payload), and reuse the computed length for the subsequent memcpy.

Copilot uses AI. Check for mistakes.
Comment on lines +559 to +562
if (tmp3 && strlen(tmp3) > MAXDNAME) {
errPtr = "Parent hash_string is too long";
goto MERROR;
}
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

This adds new input validation for '&hash' tokens but there’s no regression coverage for the new failure mode or the boundary condition (hash length == MAXDNAME). Since this file already contains EXCLUSIVE_REGRESSION_TEST(PARENTSELECTION), please add a test that exercises an overlong hash string (expecting the parse to fail with the new error) and a max-length hash string (expecting it to be accepted).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[BUG] Multiple Intra-Object Overflows in ParentSelection.cc (hash_string)

2 participants