Permalink
Browse files

Skeleton: generate proper keys for tags.

Instead of calculating all necessary keys, then attributing keys
of the first path to all paths, write proper keys for each path.

Found by slyfox's fuzzer. :)
  • Loading branch information...
skvadrik committed Nov 18, 2016
1 parent 10b51aa commit 2db0433b08bbda2d872eeae26b159a0d5e2daf2a
Showing with 8 additions and 10 deletions.
  1. +8 −10 re2c/src/ir/skeleton/generate_data.cc
@@ -199,16 +199,14 @@ static void write_keys(const path_t &path, const Skeleton &skel,
// keys: 1 - scanned length, 2 - matched length, 3 - matched rule, the rest - tags
const size_t nkey = 3 + htag - ltag;
key_t *keys = new key_t[nkey * width], *k = keys;
- // 1st path
- *k++ = to_le(static_cast<key_t>(path.len()));
- *k++ = to_le(static_cast<key_t>(matched));
- *k++ = to_le(rule2key<key_t>(rule, skel.defrule));
- for (size_t t = ltag; t < htag; ++t) {
- *k++ = to_le(static_cast<key_t>(tags[vers[t]]));
- }
- // remaining paths: copy-paste keys from 1st path
- for (size_t w = 1; w < width; ++w, k += nkey) {
- memcpy(k, keys, nkey * sizeof(key_t));
+ for (size_t w = 0; w < width; ++w) {
+ *k++ = to_le(static_cast<key_t>(path.len()));
+ *k++ = to_le(static_cast<key_t>(matched));
+ *k++ = to_le(rule2key<key_t>(rule, skel.defrule));
+ const size_t *ts = &tags[w * nver];
+ for (size_t t = ltag; t < htag; ++t) {
+ *k++ = to_le(static_cast<key_t>(ts[vers[t]]));
+ }
}
// dump to file
fwrite(keys, sizeof(key_t), nkey * width, file);

0 comments on commit 2db0433

Please sign in to comment.