header.pl: Fix parsing BOOTP leases

Message ID 20240515132003.1788345-1-michael.tremer@ipfire.org
State Staged
Commit 6515a2780201e9209e370cd4562bef5cb771f1a5
Headers
Series header.pl: Fix parsing BOOTP leases |

Commit Message

Michael Tremer May 15, 2024, 1:20 p.m. UTC
  If the lease has been handed out over BOOTP, it will never expire.
However, the parser did not account for this case at all which is fixed
in this patch.

Fixes: #13689 - BOOTP breaks the list of DHCP leases due to erroneous parsing
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
---
 config/cfgroot/header.pl | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
  

Comments

Bernhard Bitsch May 20, 2024, 10 a.m. UTC | #1
Reviewed-by: Bernhard Bitsch <bbitsch@ipfire.org>

Am 15.05.2024 um 15:20 schrieb Michael Tremer:
> If the lease has been handed out over BOOTP, it will never expire.
> However, the parser did not account for this case at all which is fixed
> in this patch.
> 
> Fixes: #13689 - BOOTP breaks the list of DHCP leases due to erroneous parsing
> Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
> ---
>   config/cfgroot/header.pl | 8 ++++++--
>   1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/config/cfgroot/header.pl b/config/cfgroot/header.pl
> index 5164e9731..a67ff92ee 100644
> --- a/config/cfgroot/header.pl
> +++ b/config/cfgroot/header.pl
> @@ -454,12 +454,16 @@ END
>   			$hostname = "";
>   		}
>   
> -		if ($line =~ /^\s*ends/) {
> -			$line =~ /(\d+)\/(\d+)\/(\d+) (\d+):(\d+):(\d+)/;
> +		if ($line =~ /^\s*ends \d (\d+)\/(\d+)\/(\d+) (\d+):(\d+):(\d+)/) {
>   			$endtime = timegm($6, $5, $4, $3, $2 - 1, $1 - 1900);
>   			($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $dst) = localtime($endtime);
>   			$endtime_print = sprintf ("%02d/%02d/%d %02d:%02d:%02d",$mday,$mon+1,$year+1900,$hour,$min,$sec);
>   			$expired = $endtime < time();
> +
> +		} elsif ($line =~ /^\s*ends never/) {
> +			$endtime = 0;
> +			$endtime_print = $Lang::tr{'never'};
> +			$expired = 0;
>   		}
>   
>   		if ($line =~ /^\s*hardware ethernet/) {
  

Patch

diff --git a/config/cfgroot/header.pl b/config/cfgroot/header.pl
index 5164e9731..a67ff92ee 100644
--- a/config/cfgroot/header.pl
+++ b/config/cfgroot/header.pl
@@ -454,12 +454,16 @@  END
 			$hostname = "";
 		}
 
-		if ($line =~ /^\s*ends/) {
-			$line =~ /(\d+)\/(\d+)\/(\d+) (\d+):(\d+):(\d+)/;
+		if ($line =~ /^\s*ends \d (\d+)\/(\d+)\/(\d+) (\d+):(\d+):(\d+)/) {
 			$endtime = timegm($6, $5, $4, $3, $2 - 1, $1 - 1900);
 			($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $dst) = localtime($endtime);
 			$endtime_print = sprintf ("%02d/%02d/%d %02d:%02d:%02d",$mday,$mon+1,$year+1900,$hour,$min,$sec);
 			$expired = $endtime < time();
+
+		} elsif ($line =~ /^\s*ends never/) {
+			$endtime = 0;
+			$endtime_print = $Lang::tr{'never'};
+			$expired = 0;
 		}
 
 		if ($line =~ /^\s*hardware ethernet/) {