[pmg-devel] [PATCH pmg-log-tracker 2/2] parse_number: prevent panic on empty input
Fabian Grünbichler
f.gruenbichler at proxmox.com
Wed Jun 10 15:22:53 CEST 2020
if data is empty or the caller requested 0 digits, we can return early.
Signed-off-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
---
src/main.rs | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/main.rs b/src/main.rs
index 94a6247..613cecd 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2187,6 +2187,9 @@ fn parse_qid(data: &[u8], max: usize) -> Option<(&[u8], &[u8])> {
/// Parse a number. Returns a tuple of (parsed_number, remaining_text) or None.
fn parse_number(data: &[u8], max_digits: usize) -> Option<(usize, &[u8])> {
let max = max_digits.min(data.len());
+ if max == 0 {
+ return None;
+ }
match data.iter().take(max).position(|b| !b.is_ascii_digit()) {
Some(n) if n == 0 => None,
--
2.20.1
More information about the pmg-devel
mailing list