Skip to content

Commit

Permalink
Ensure Windows entity names are sanitized
Browse files Browse the repository at this point in the history
  • Loading branch information
ohsayan committed Mar 30, 2022
1 parent 2ccd771 commit c984bd2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
16 changes: 12 additions & 4 deletions server/src/queryengine/parser.rs
Expand Up @@ -202,11 +202,19 @@ impl<'a> Entity<'a> {
}
#[inline(always)]
fn verify_entity_name(input: &[u8]) -> Result<&[u8], &'static [u8]> {
let valid_name = input.len() < 65
let mut valid_name = input.len() < 65
&& encoding::is_utf8(input)
&& unsafe { VALID_CONTAINER_NAME.is_match(str::from_utf8_unchecked(input)) }
&& input != b"PARTMAP"
&& input != b"PRELOAD";
&& unsafe { VALID_CONTAINER_NAME.is_match(str::from_utf8_unchecked(input)) };
#[cfg(windows)]
{
// paths on Windows are case insensitive that's why this is necessary
valid_name &=
!(input.eq_ignore_ascii_case(b"PRELOAD") || input.eq_ignore_ascii_case(b"PARTMAP"));
}
#[cfg(not(windows))]
{
valid_name &= (input != b"PRELOAD") && (input != b"PARTMAP");
}
if compiler::likely(valid_name && !input.is_empty()) {
// valid name
Ok(input)
Expand Down
13 changes: 13 additions & 0 deletions server/src/queryengine/tests.rs
Expand Up @@ -365,4 +365,17 @@ mod entity_parser_tests {
responses::groups::BAD_CONTAINER_NAME
);
}
#[test]
fn ks_or_table_with_preload_or_partmap() {
let badname = byt!("PARTMAP");
assert_eq!(
Entity::from_slice(&badname).unwrap_err(),
responses::groups::BAD_CONTAINER_NAME
);
let badname = byt!("PRELOAD");
assert_eq!(
Entity::from_slice(&badname).unwrap_err(),
responses::groups::BAD_CONTAINER_NAME
);
}
}

0 comments on commit c984bd2

Please sign in to comment.