Skip to content

Commit 8de1bc6

Browse files
Alexander Krotovlink2xt
authored andcommitted
sql: fix potential panic in maybe_add_file
When maybe_add_file was called with "$BLOBDIR" it tried to remove 9 bytes from the string, while it only contains 8.
1 parent cf09942 commit 8de1bc6

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/sql.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ fn is_file_in_use(files_in_use: &HashSet<String>, namespc_opt: Option<&str>, nam
593593
}
594594

595595
fn maybe_add_file(files_in_use: &mut HashSet<String>, file: impl AsRef<str>) {
596-
if !file.as_ref().starts_with("$BLOBDIR") {
596+
if !file.as_ref().starts_with("$BLOBDIR/") {
597597
return;
598598
}
599599

@@ -1312,10 +1312,12 @@ mod test {
13121312
maybe_add_file(&mut files, "$BLOBDIR/hello");
13131313
maybe_add_file(&mut files, "$BLOBDIR/world.txt");
13141314
maybe_add_file(&mut files, "world2.txt");
1315+
maybe_add_file(&mut files, "$BLOBDIR");
13151316

13161317
assert!(files.contains("hello"));
13171318
assert!(files.contains("world.txt"));
13181319
assert!(!files.contains("world2.txt"));
1320+
assert!(!files.contains("$BLOBDIR"));
13191321
}
13201322

13211323
#[test]

0 commit comments

Comments
 (0)