Add check that ByteMatcher pattern has the mask applied

This commit is contained in:
Jonathan Giddy 2016-02-23 13:46:53 +00:00
parent 480cb385fc
commit 6ea656c6c5

View file

@ -299,7 +299,7 @@ impl ByteMatcher {
.and_then(|start|
if data[start..].iter()
.zip(self.pattern.iter()).zip(self.mask.iter())
.all(|((&data, &pattern), &mask)| (data & mask) == (pattern & mask)) {
.all(|((&data, &pattern), &mask)| (data & mask) == pattern) {
Some(start + self.pattern.len())
} else {
None
@ -328,6 +328,14 @@ impl MIMEChecker for ByteMatcher {
self.content_type.0, self.content_type.1
))
}
if self.pattern.iter().zip(self.mask.iter()).any(
|(&pattern, &mask)| pattern & mask != pattern
) {
return Err(format!(
"Pattern not pre-masked for {}/{}",
self.content_type.0, self.content_type.1
))
}
Ok(())
}
}