mirror of
https://github.com/zeek/zeek.git
synced 2025-10-08 17:48:21 +00:00
Fix using patterns stored as table/set indices
Pattern values used as table/set indices are stored in serialized form using just the pattern text, but re-creating the value from that didn't fully initialize/compile the regex matcher after (re-)creating it from that pattern text.
This commit is contained in:
parent
e66148a13a
commit
da56cd44d9
3 changed files with 56 additions and 0 deletions
|
@ -891,6 +891,11 @@ const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0,
|
||||||
re = new RE_Matcher(kp1, kp1 + len[0]);
|
re = new RE_Matcher(kp1, kp1 + len[0]);
|
||||||
kp1 += len[0] + len[1];
|
kp1 += len[0] + len[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( ! re->Compile() )
|
||||||
|
reporter->InternalError("failed compiling table/set key pattern: %s",
|
||||||
|
re->PatternText());
|
||||||
|
|
||||||
*pval = make_intrusive<PatternVal>(re);
|
*pval = make_intrusive<PatternVal>(re);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
/^?(a)$?/, F
|
||||||
|
/^?(b)$?/, F
|
||||||
|
/^?(o)$?/, T
|
||||||
|
---
|
||||||
|
/^?(a)$?/, F
|
||||||
|
/^?(b)$?/, F
|
||||||
|
/^?(o)$?/, T
|
||||||
|
---
|
||||||
|
/^?(a)$?/, F
|
||||||
|
/^?(b)$?/, F
|
||||||
|
/^?(o)$?/, T
|
||||||
|
---
|
||||||
|
/^?(a)$?/, F
|
||||||
|
/^?(b)$?/, F
|
||||||
|
/^?(o)$?/, T
|
||||||
|
---
|
||||||
|
/^?(o)$?/, T
|
||||||
|
/^?(b)$?/, F
|
||||||
|
/^?(a)$?/, F
|
32
testing/btest/language/patterns-stored-in-containers.zeek
Normal file
32
testing/btest/language/patterns-stored-in-containers.zeek
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
# @TEST-EXEC: zeek -b %INPUT >out
|
||||||
|
# @TEST-EXEC: btest-diff out
|
||||||
|
|
||||||
|
local test_string = "foo";
|
||||||
|
local myvec: vector of pattern = vector(/a/, /b/, /o/);
|
||||||
|
local myset: set[pattern] = {/a/, /b/, /o/};
|
||||||
|
local tk: table[pattern] of count = {[/a/] = 0, [/b/] = 1, [/o/] = 2};
|
||||||
|
local tv: table[count] of pattern = {[0] = /a/, [1] = /b/, [2] = /o/};
|
||||||
|
|
||||||
|
print /a/, /a/ in test_string;
|
||||||
|
print /b/, /b/ in test_string;
|
||||||
|
print /o/, /o/ in test_string;
|
||||||
|
|
||||||
|
print "---";
|
||||||
|
|
||||||
|
for ( i in myvec )
|
||||||
|
print myvec[i], myvec[i] in test_string;
|
||||||
|
|
||||||
|
print "---";
|
||||||
|
|
||||||
|
for ( p in myset )
|
||||||
|
print p, p in test_string;
|
||||||
|
|
||||||
|
print "---";
|
||||||
|
|
||||||
|
for ( k, v in tk )
|
||||||
|
print k, k in test_string;
|
||||||
|
|
||||||
|
print "---";
|
||||||
|
|
||||||
|
for ( key, val in tv )
|
||||||
|
print val, val in test_string;
|
Loading…
Add table
Add a link
Reference in a new issue