From 50ce98d5d099441ebf69ab7dedf7aef78845107d Mon Sep 17 00:00:00 2001 From: Ryan Avella <41444142+ryanavella@users.noreply.github.com> Date: Sat, 27 Aug 2022 16:32:48 -0700 Subject: [PATCH] Reject names with null-bytes in NamedLock::create. --- src/lib.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index c0f452c..c2a8fea 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -87,7 +87,10 @@ impl NamedLock { // so we block the `/` character. // // On Windows `\` character is invalid. - if name.contains('/') || name.contains('\\') { + // + // Both platforms expect null-terminated strings, + // so we block null-bytes. + if name.chars().any(|c| matches!(c, '\0' | '/' | '\\')) { return Err(Error::InvalidCharacter); }