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

Thomas Lamprecht t.lamprecht at proxmox.com
Wed Jun 17 09:26:29 CEST 2020


Am 6/10/20 um 3:22 PM schrieb Fabian Grünbichler:
> '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))
>  }
> 

applied series, thanks!



More information about the pmg-devel mailing list