Shifting long long value more than 63 bits is UB#580
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 18fd9576da
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| long long Arguments::hash(const char *arg) { | ||
| long long h = 0; | ||
| for (int shift = 0; *arg != 0; shift += 5) { | ||
| for (int shift = 0; *arg != 0 && shift < 60; shift += 5) { |
There was a problem hiding this comment.
Reject overlong option suffixes
For arguments longer than 12 characters, this now silently ignores the rest of the option name, so malformed inputs whose first twelve bytes collide with a valid CASE are accepted instead of being recorded as _unknown_arg. For example, start x hashes the same as start because the seven spaces occupy the remaining hashed slots and the trailing x is discarded, which sets ACTION_START with no unknown-argument warning; overlong names should instead produce a non-matching hash once *arg remains after the 12th character.
Useful? React with 👍 / 👎.
CI Test ResultsRun: #27033368721 | Commit:
Status Overview
Legend: ✅ passed | ❌ failed | ⚪ skipped | 🚫 cancelled Summary: Total: 32 | Passed: 32 | Failed: 0 Updated: 2026-06-05 18:55:36 UTC |
What does this PR do?:
Shifting long long value more than 63 bits is UB, break out the loop before
shiftreaches invalid value.Besides, the fix matching the HASH macro's highest term s[11] << 55.
Motivation:
Improve stability and correctness.
Additional Notes:
How to test the change?:
fuzz_argumentstest now passes.For Datadog employees:
credentials of any kind, I've requested a review from
@DataDog/security-design-and-guidance.Unsure? Have a question? Request a review!