Skip to content

Commit 9d2d0bb

Browse files
authored
fix(obfuscation/memcached): fuzzing fix (#1695)
# What does this PR do? Ran a [fuzzer](https://github.com/DataDog/obfuscation-parity-tester/blob/main/crates/fuzzer/src/lib.rs) to find output difference between this obfuscator and the agent's obfuscator, fixed issues one by one, even the nonsensical edge cases. This one fixes 1 fuzzing testcase: memcached_fuzzing_2126976840 # Motivation Reach 100% parity between obfuscation libs. # Additional Notes # How to test the change? Co-authored-by: oscar.ledauphin <oscar.ledauphin@datadoghq.com>
1 parent b6e1ba4 commit 9d2d0bb

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

libdd-trace-obfuscation/src/memcached.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@ pub fn obfuscate_memcached_string(cmd: &str) -> String {
99
// a new line. For non-storage commands, this will have no effect.
1010
// [1]: https://github.com/memcached/memcached/blob/master/doc/protocol.txt
1111
let split: Vec<&str> = cmd.splitn(2, "\r\n").collect();
12-
if let Some(res) = split.first() {
13-
res.to_string()
14-
} else {
15-
cmd.to_string()
16-
}
12+
let res = split.first().copied().unwrap_or(cmd);
13+
res.trim().to_string()
1714
}
1815

1916
#[cfg(test)]
@@ -29,6 +26,7 @@ mod tests {
2926
[test_obfuscate_memcached_3] ["add newkey 0 60 5\r\nvalue"] ["add newkey 0 60 5"];
3027
[test_obfuscate_memcached_4] ["add newkey 0 60 5\r\nvalue\r\nvalue1"] ["add newkey 0 60 5"];
3128
[test_obfuscate_memcached_5] ["decr mykey 5"] ["decr mykey 5"];
29+
[fuzzing_2126976840] ["\t"] [""];
3230
)]
3331
#[test]
3432
fn test_name() {

0 commit comments

Comments
 (0)