[pmg-devel] [PATCH pmg-log-tracker 1/2] parse_time: prevent panic on truncated input

Fabian Grünbichler f.gruenbichler at proxmox.com
Wed Jun 10 15:22:52 CEST 2020


'advancing' a slice by one is only a good idea if there is more data.

Signed-off-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
---
there's probably a more elegant way for the second hunk.. ?

 src/main.rs | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/main.rs b/src/main.rs
index 8b497cd..94a6247 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2271,6 +2271,10 @@ fn parse_time<'a>(
 
     ltime += (mday - 1) as i64;
 
+    if data.len() == 0 {
+        return None;
+    }
+
     let data = &data[1..];
 
     let (hour, data) = match parse_number(data, 2) {
@@ -2321,7 +2325,10 @@ fn parse_time<'a>(
     ltime *= 60;
     ltime += sec as i64;
 
-    let data = &data[1..];
+    let data = match data.len() {
+        0 => &[],
+        _ => &data[1..],
+    };
 
     Some((ltime, data))
 }
-- 
2.20.1




More information about the pmg-devel mailing list