Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions libyara/modules/math/math.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ define_function(data_serial_correlation)
YR_MEMORY_BLOCK_ITERATOR* iterator = context->iterator;

double sccun = 0;
double sccfirst = 0;
double scclast = 0;
double scct1 = 0;
double scct2 = 0;
Expand Down Expand Up @@ -348,6 +349,9 @@ define_function(data_serial_correlation)
for (i = 0; i < data_len; i++)
{
sccun = (double) *(block_data + data_offset + i);
if (i == 0) {
sccfirst = sccun;
}
scct1 += scclast * sccun;
scct2 += sccun;
scct3 += sccun * sccun;
Expand All @@ -373,7 +377,7 @@ define_function(data_serial_correlation)
if (!past_first_block)
return_float(YR_UNDEFINED);

scct1 += scclast * sccun;
scct1 += scclast * sccfirst;
scct2 *= scct2;

scc = total_len * scct3 - scct2;
Expand Down Expand Up @@ -408,7 +412,9 @@ define_function(string_serial_correlation)
scclast = sccun;
}

scct1 += scclast * sccun;
if (s->length > 0) {
scct1 += scclast * (double) s->c_string[0];
}
scct2 *= scct2;

scc = s->length * scct3 - scct2;
Expand Down
4 changes: 2 additions & 2 deletions tests/test-math.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,15 @@ int main(int argc, char** argv)
"import \"math\" \
rule test { \
condition: \
math.serial_correlation(\"BCAB\") == -0.5 \
math.serial_correlation(\"BCA\") == -0.5 \
}",
NULL);

assert_true_rule_blob(
"import \"math\" \
rule test { \
condition: \
math.serial_correlation(1, 4) == -0.5 \
math.serial_correlation(1, 3) == -0.5 \
}",
"ABCABC");

Expand Down