History

fix: validate incoming conifguration keys when interpreting envirnoment variables. (#331)

Sebastian Thiel committed 4 years ago

Commit 0d07ef11 parent 9750b7a1 file · +5 −4Browse files

Unified · Split

git-config/src/file/init/from_env.rs+5−4
@@ -1,7 +1,6 @@
1+use std::convert::TryFrom;
12 use std::{borrow::Cow, path::PathBuf};
23
3−use bstr::BString;
4−
54 use crate::{
65 file::{from_paths, init::resolve_includes},
76 parse::section,
@@ -27,6 +26,8 @@ pub enum Error { · 19 unmodified lines
2726 FromPathsError(#[from] from_paths::Error),
2827 #[error(transparent)]
2928 Section(#[from] section::header::Error),
29+ #[error(transparent)]
30+ Key(#[from] section::key::Error),
3031 }
3132
3233 /// Instantiation from environment variables
@@ -112,8 +113,8 @@ impl File<'static> { · 79 unmodified lines
112113 };
113114
114115 section.push(
115− section::Key(BString::from(key).into()),
116− git_path::into_bstr(PathBuf::from(value)).as_ref(),
116+ section::Key::try_from(key.to_owned())?,
117+ git_path::os_str_into_bstr(&value).expect("no illformed UTF-8").as_ref(),
117118 );
118119 }
119120 None => {