Merge pull request #136 from ephraimkunz/fix-bool-fuzz-issue

Fix unwrap being hit in macro when malicious input is given
This commit is contained in:
Marc-Antoine ARNAUD 2022-03-25 10:04:00 +01:00 committed by GitHub
commit 790a9f10f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View File

@ -107,3 +107,30 @@ fn option_struct() {
);
test_for_type!(Option::<Test>, None, None);
}
#[test]
fn option_bool_no_crash_on_bad_input() {
init();
#[derive(Debug, PartialEq, YaDeserialize, YaSerialize)]
struct Test {
field: SubTest,
}
#[derive(Debug, PartialEq, YaDeserialize, YaSerialize)]
struct SubTest {
#[yaserde(attribute)]
content: Option<bool>,
}
impl Default for SubTest {
fn default() -> Self {
SubTest { content: None }
}
}
let content = "<field><content>/<R/";
let result: Result<Test, String> = yaserde::de::from_str(content);
assert!(result.is_err());
}

View File

@ -116,7 +116,7 @@ pub fn parse(
self,
v: &str,
) -> ::std::result::Result<Self::Value, ::std::string::String> {
::std::result::Result::Ok(#field_type::from_str(#map_if_bool).unwrap())
#field_type::from_str(#map_if_bool).map_err(|e| e.to_string())
}
}
})