Skip to content

Commit

Permalink
Fix out-of-bounds array index (#597)
Browse files Browse the repository at this point in the history
Co-authored-by: Lucio Franco <luciofranco14@gmail.com>
  • Loading branch information
andrewhickman and LucioFranco authored Feb 28, 2022
1 parent ae84e7d commit 3ae6646
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion prost-build/src/code_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ fn unescape_c_escape_string(s: &str) -> Vec<u8> {
dst.push(octal);
}
b'x' | b'X' => {
if p + 2 > len {
if p + 3 > len {
panic!(
"invalid c-escaped default binary value ({}): incomplete hex value",
s
Expand Down Expand Up @@ -1074,6 +1074,12 @@ mod tests {
);
}

#[test]
#[should_panic(expected = "incomplete hex value")]
fn test_unescape_c_escape_string_incomplete_hex_value() {
unescape_c_escape_string(r#"\x1"#);
}

#[test]
fn test_strip_enum_prefix() {
assert_eq!(strip_enum_prefix("Foo", "FooBar"), "Bar");
Expand Down

0 comments on commit 3ae6646

Please sign in to comment.