Repository navigation
util-byte: add string extraction limited to a buffer - v1 - #16729
victorjulien wants to merge 5 commits into
Conversation
suricata-review-bot
left a comment
There was a problem hiding this comment.
AI-generated review.
Verdict: approve
No high- or medium-severity findings.
Automated at commit 70b7c24c1043 using Claude Code with claude-opus-5-5/xhigh. Run: 5c3a33ad3b09332d.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16729 +/- ##
==========================================
- Coverage 83.98% 83.98% -0.01%
==========================================
Files 1008 1008
Lines 286748 286904 +156
==========================================
+ Hits 240832 240952 +120
- Misses 45916 45952 +36
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
|
There was a previous PR with some comments of mine that are unanswered like #16657 (comment) |
|
Information: QA ran without warnings. Pipeline = 36132 |
ByteExtractString() treated a length of 0 as a NUL-terminated string and ran strtoull() on the caller's pointer. Inspection buffers are not guaranteed to be NUL terminated, so a length of 0 could make strtoull() read past the end of one. Add ByteExtractStringUint64Bounded(), which also takes the number of bytes that can be read. With a length of 0 it finds the end of the number without reading past that limit. It skips leading whitespace and zeros before applying the 23-byte limit that ByteExtractString() applies to len, so every number that fits in a uint64_t converts in full. It returns the number of bytes consumed, counting leading whitespace and any sign. Issue: 9089
byte_test with the string option and a byte count of 0 passed the count to ByteExtractStringUint64(), which treated a length of 0 as a NUL- terminated string and ran strtoull() on the inspection buffer. Inspection buffers are not guaranteed to be NUL terminated, so the conversion could read digits past the end of the buffer, and the comparison used them. The count can come from a byte_extract variable, so a packet could set it to 0. Call ByteExtractStringUint64Bounded() with the number of bytes left in the buffer, and do not match when none are left. A number that runs past the end of the buffer converts only the bytes inside it, so a number cut off by the end of the buffer can now match. Rules with a count of 0 still load, and a number inside the buffer converts as it did before, including one padded with more than 23 leading zeros or spaces. Issue: 9089
byte_jump with the string option and a byte count of 0 passed the count to ByteExtractStringUint64(), which treated a length of 0 as a NUL- terminated string and ran strtoull() on the inspection buffer. Inspection buffers are not guaranteed to be NUL terminated, so the conversion could read digits past the end of the buffer. The jump distance came from those digits. For a jump that is neither from_beginning nor from_end, the number of bytes the conversion consumed was also added to the jump target. The count can come from a byte_extract variable, so a packet could set it to 0. Call ByteExtractStringUint64Bounded() with the number of bytes left in the buffer, and do not match when none are left. A number that runs past the end of the buffer converts only the bytes inside it. Rules with a count of 0 still load. A number inside the buffer converts as it did before, and the jump steps over the same bytes as before. Issue: 9089
byte_extract with the string option and a byte count of 0 passed the count to ByteExtractStringUint64(), which treated a length of 0 as a NUL-terminated string and ran strtoull() on the inspection buffer. Inspection buffers are not guaranteed to be NUL terminated, so the conversion could read digits past the end of the buffer into the extracted variable and move the read position past the end of the buffer. Call ByteExtractStringUint64Bounded() with the number of bytes left in the buffer, and do not match when none are left. A number that runs past the end of the buffer converts only the bytes inside it. A number inside the buffer converts as it did before, and the read position ends right after it. Issue: 9089
Content-Length: 0 leaves a one-byte inspection value; the byte after it in the pool can be a digit. The bounded conversion must stop at the avail boundary, which ByteTest17 does not exercise at avail 1. Ticket: OISF#9089.
70b7c24 to
2779ec8
Compare
suricata-review-bot
left a comment
There was a problem hiding this comment.
AI-generated review.
Verdict: comment
Previous feedback:
- Not addressed — catenacyber's comment — The code matches the reviewed earlier version patch for patch; the nbytes-per-base consistency, byte_extract hex limit, docs and len/avail questions remain unanswered and unchanged.
No high- or medium-severity findings.
Automated at commit 2779ec895e7f using Claude Code with claude-opus-5-5/xhigh. Run: cd579509e72589a7.
Ticket: https://redmine.openinfosecfoundation.org/issues/9089
This branch carries the upstream v2 fix for the zero-byte-count
string conversion (ByteExtractStringUint64Bounded and the three
detect keywords), rebased on main, plus a unit case for the
one-byte value at the avail boundary. byte_test, byte_jump and
byte_extract with the string option and a byte count of 0 previously
converted the caller's buffer in place and ran on until a non-digit:
for a one-byte value (a Content-Length: 0) the stale byte after it in
the pool could shift the parse, and the rule verdict varied from run to
run.
byte_math needs no change: its match validation rejects a count below 1,
so the unbounded path is unreachable there.
SV_BRANCH=OISF/suricata-verify#3547