Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/topic/robin/gh-1875-sync-fix'
Browse files Browse the repository at this point in the history
* origin/topic/robin/gh-1875-sync-fix:
  Fix potential nullptr dereference when comparing streams.
  • Loading branch information
rsmmr committed Sep 30, 2024
2 parents a49287e + f1f7a92 commit 943dea8
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ inout = "inout"
ocur = "ocur"
bigsur = "Big Sur"
Smoot = "Smoot"
ba = "ba"
Datas = "Datas"
7 changes: 7 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
1.12.0-dev.124 | 2024-09-30 17:43:41 +0200

* GH-1875: Fix potential nullptr dereference when comparing streams. (Robin Sommer, Corelight)

Because we are operating on unsafe iterators, need to catch when one
goes out of bounds.

1.12.0-dev.122 | 2024-09-30 14:18:09 +0200

* GH-1874: Add new library function `spicy::bytes_to_mac`. (Robin Sommer, Corelight)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.12.0-dev.122
1.12.0-dev.124
8 changes: 7 additions & 1 deletion hilti/runtime/src/types/stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,9 @@ bool stream::View::operator==(const View& other) const {
auto j = other.unsafeBegin();

while ( i != unsafeEnd() ) {
if ( ! i.chunk() || ! j.chunk() )
return (i.chunk() == j.chunk() && i.offset() == j.offset()); // same out-of-bounds iterators

if ( i.chunk()->isGap() != j.chunk()->isGap() )
return false;

Expand All @@ -586,6 +589,9 @@ bool stream::View::operator==(const Bytes& other) const {
auto j = other.begin();

while ( i != unsafeEnd() ) {
if ( ! i.chunk() ) // out-of-bounds, cannot match
return false;

if ( *i++ != *j++ )
return false;
}
Expand All @@ -594,7 +600,7 @@ bool stream::View::operator==(const Bytes& other) const {
}

std::string hilti::rt::detail::adl::to_string(const stream::SafeConstIterator& x, adl::tag /*unused*/) {
auto str = [](auto x) {
auto str = [](const auto& x) {
auto y = x + 10;
auto v = stream::View(x, y);
if ( y.isEnd() )
Expand Down
14 changes: 14 additions & 0 deletions tests/spicy/types/unit/synchronize-after-with-trim.spicy
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# @TEST-EXEC: printf ba | spicy-driver -d %INPUT
#
# @TEST-DOC: Tests `%synchronize-after` with a fully trimmed view; regression test for #1875.

module RESP;

public type Datas = unit {
: (Data &synchronize)[] { confirm; }
};

type Data = unit {
%synchronize-after=b"a";
ty: uint8 &requires=($$ < 5);
};

0 comments on commit 943dea8

Please sign in to comment.