From 120c3641d2d4c22b8630da017bedc0a8522b6130 Mon Sep 17 00:00:00 2001 From: Oscar Le Dauphin Date: Thu, 5 Mar 2026 17:04:47 +0100 Subject: [PATCH] fix(memcached): trim whitespace from result to match Go's strings.TrimSpace Go's ObfuscateMemcachedString calls strings.TrimSpace() on the result after splitting on \r\n. Rust was not trimming, causing a tab-only input to return "\t" instead of "". Fixes fuzzing testcase: memcached_fuzzing_2126976840 --- libdd-trace-obfuscation/src/memcached.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/libdd-trace-obfuscation/src/memcached.rs b/libdd-trace-obfuscation/src/memcached.rs index 30f6a1fef4..14c7c96b52 100644 --- a/libdd-trace-obfuscation/src/memcached.rs +++ b/libdd-trace-obfuscation/src/memcached.rs @@ -9,11 +9,8 @@ pub fn obfuscate_memcached_string(cmd: &str) -> String { // a new line. For non-storage commands, this will have no effect. // [1]: https://github.com/memcached/memcached/blob/master/doc/protocol.txt let split: Vec<&str> = cmd.splitn(2, "\r\n").collect(); - if let Some(res) = split.first() { - res.to_string() - } else { - cmd.to_string() - } + let res = split.first().copied().unwrap_or(cmd); + res.trim().to_string() } #[cfg(test)] @@ -29,6 +26,7 @@ mod tests { [test_obfuscate_memcached_3] ["add newkey 0 60 5\r\nvalue"] ["add newkey 0 60 5"]; [test_obfuscate_memcached_4] ["add newkey 0 60 5\r\nvalue\r\nvalue1"] ["add newkey 0 60 5"]; [test_obfuscate_memcached_5] ["decr mykey 5"] ["decr mykey 5"]; + [fuzzing_2126976840] ["\t"] [""]; )] #[test] fn test_name() {