From a3fe56a66ace9ab64af275ef6b4ff0151e5fcbf9 Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Sun, 15 Sep 2024 09:52:50 +0000 Subject: [PATCH 1/2] Check if argument of SET instructions is valid --- pio-parser/src/lib.rs | 8 +++++++- src/lib.rs | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/pio-parser/src/lib.rs b/pio-parser/src/lib.rs index f943871..0426af6 100644 --- a/pio-parser/src/lib.rs +++ b/pio-parser/src/lib.rs @@ -189,7 +189,13 @@ impl<'i> ParsedOperands<'i> { }, ParsedOperands::SET { destination, data } => InstructionOperands::SET { destination: *destination, - data: data.reify(state) as u8, + data: { + let arg = data.reify(state); + if arg < 0 || arg > 0x1f { + panic!("SET argument out of range: {}", arg); + } + arg as u8 + }, }, } } diff --git a/src/lib.rs b/src/lib.rs index 76305a3..b06e260 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -273,7 +273,12 @@ impl InstructionOperands { *index | (if *relative { 0b10000 } else { 0 }), ) } - InstructionOperands::SET { destination, data } => (*destination as u8, *data), + InstructionOperands::SET { destination, data } => { + if *data > 0x1f { + panic!("SET argument out of range"); + } + (*destination as u8, *data) + } } } From 2ceffff1d82de296ba0234db9404ff0f8ae6d28c Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Sun, 15 Sep 2024 20:49:04 +0000 Subject: [PATCH 2/2] allow(clippy::manual_range_contains) --- pio-parser/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/pio-parser/src/lib.rs b/pio-parser/src/lib.rs index 0426af6..b8e2ffb 100644 --- a/pio-parser/src/lib.rs +++ b/pio-parser/src/lib.rs @@ -1,4 +1,5 @@ // PIO instr grouping is 3/5/3/5 +#![allow(clippy::manual_range_contains)] #![allow(clippy::unusual_byte_groupings)] #![allow(clippy::upper_case_acronyms)]