Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions helpers.build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,6 @@ function Get-RustUp {
Write-Verbose -Verbose "Using msrustup"
$rustup = 'msrustup'
$channel = 'ms-prod-1.95'
if ($architecture -eq 'current') {
$env:MSRUSTUP_TOOLCHAIN = "$architecture"
}
} elseif ($null -ne (Get-Command rustup -CommandType Application -ErrorAction Ignore)) {
$rustup = 'rustup'
$env:TESTING_FUNCTION_ENV = "lolwhat"
Expand Down
15 changes: 13 additions & 2 deletions lib/dsc-lib-registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ fn convert_value_data_to_offline(value_data: &RegistryValueData) -> Result<(u32,

/// Decode a null-terminated UTF-16LE byte slice to a String.
fn decode_utf16_bytes(data: &[u8]) -> String {
let u16_slice: Vec<u16> = data.chunks_exact(2)
let u16_slice: Vec<u16> = data.as_chunks::<2>().0.iter()
.map(|chunk| u16::from_le_bytes([chunk[0], chunk[1]]))
.collect();
// Strip trailing null
Expand All @@ -761,7 +761,7 @@ fn encode_utf16_bytes(s: &str) -> Vec<u8> {

/// Decode REG_MULTI_SZ: double-null-terminated list of null-terminated UTF-16LE strings.
fn decode_multi_sz(data: &[u8]) -> Vec<String> {
let u16_slice: Vec<u16> = data.chunks_exact(2)
let u16_slice: Vec<u16> = data.as_chunks::<2>().0.iter()
.map(|chunk| u16::from_le_bytes([chunk[0], chunk[1]]))
.collect();
let mut strings = Vec::new();
Expand Down Expand Up @@ -789,6 +789,17 @@ fn encode_multi_sz(strings: &[String]) -> Vec<u8> {
result.iter().flat_map(|&c| c.to_le_bytes()).collect()
}

#[test]
fn decode_utf16_bytes_ignores_incomplete_code_unit() {
assert_eq!(decode_utf16_bytes(&[b'A', 0, 0xff]), "A");
}

#[test]
fn decode_multi_sz_ignores_incomplete_code_unit() {
let data = [b'A', 0, 0, 0, 0, 0, 0xff];
assert_eq!(decode_multi_sz(&data), vec!["A"]);
}

#[test]
fn get_hklm_key() {
let reg_helper = RegistryHelper::new_from_json(r#"{"keyPath":"HKEY_LOCAL_MACHINE"}"#).unwrap();
Expand Down
9 changes: 4 additions & 5 deletions lib/dsc-lib/src/functions/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,15 @@ impl Function for Int {

fn invoke(&self, args: &[Value], _context: &Context) -> Result<Value, DscError> {
let arg = &args[0];
let value: i64;
if arg.is_string() {
let value: i64 = if arg.is_string() {
let input = arg.as_str().ok_or(DscError::FunctionArg("int".to_string(), t!("functions.int.invalidInput").to_string()))?;
let result = input.parse::<f64>().map_err(|_| DscError::FunctionArg("int".to_string(), t!("functions.int.parseStringError").to_string()))?;
value = NumCast::from(result).ok_or(DscError::FunctionArg("int".to_string(), t!("functions.int.castError").to_string()))?;
NumCast::from(result).ok_or(DscError::FunctionArg("int".to_string(), t!("functions.int.castError").to_string()))?
} else if arg.is_number() {
value = arg.as_i64().ok_or(DscError::FunctionArg("int".to_string(), t!("functions.int.parseNumError").to_string()))?;
arg.as_i64().ok_or(DscError::FunctionArg("int".to_string(), t!("functions.int.parseNumError").to_string()))?
} else {
return Err(DscError::FunctionArg("int".to_string(), t!("functions.invalidArgType").to_string()));
}
};
Ok(Value::Number(value.into()))
}
}
Expand Down
Loading