Fix subscript error with odd TZif file [BZ #28338]

Message ID 20210914054946.46372-1-eggert@cs.ucla.edu
State Committed
Commit 645277434a42efc547d2cac8bfede4da10b4049f
Delegated to: Adhemerval Zanella Netto
Headers
Series Fix subscript error with odd TZif file [BZ #28338] |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent
dj/TryBot-32bit success Build for i686

Commit Message

Paul Eggert Sept. 14, 2021, 5:49 a.m. UTC
  * time/tzfile.c (__tzfile_compute): Fix unlikely off-by-one bug
that accessed before start of an array when an oddball-but-valid
TZif file was queried with an unusual time_t value.
---
 time/tzfile.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
  

Comments

Adhemerval Zanella Sept. 28, 2021, 5:42 p.m. UTC | #1
On 14/09/2021 02:49, Paul Eggert wrote:
> * time/tzfile.c (__tzfile_compute): Fix unlikely off-by-one bug
> that accessed before start of an array when an oddball-but-valid
> TZif file was queried with an unusual time_t value.

LGTM, thanks.  Do we have a testcase to trigger it by chance?

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

> ---
>  time/tzfile.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/time/tzfile.c b/time/tzfile.c
> index 4377018a55..190a777152 100644
> --- a/time/tzfile.c
> +++ b/time/tzfile.c
> @@ -765,8 +765,7 @@ __tzfile_compute (__time64_t timer, int use_localtime,
>    *leap_correct = leaps[i].change;
>  
>    if (timer == leaps[i].transition /* Exactly at the transition time.  */
> -      && ((i == 0 && leaps[i].change > 0)
> -	  || leaps[i].change > leaps[i - 1].change))
> +      && (leaps[i].change > (i == 0 ? 0 : leaps[i - 1].change)))
>      {
>        *leap_hit = 1;
>        while (i > 0
>
  
Paul Eggert Sept. 28, 2021, 6:40 p.m. UTC | #2
On 9/28/21 10:42, Adhemerval Zanella wrote:
> LGTM, thanks.  Do we have a testcase to trigger it by chance?

Sorry, no.
  

Patch

diff --git a/time/tzfile.c b/time/tzfile.c
index 4377018a55..190a777152 100644
--- a/time/tzfile.c
+++ b/time/tzfile.c
@@ -765,8 +765,7 @@  __tzfile_compute (__time64_t timer, int use_localtime,
   *leap_correct = leaps[i].change;
 
   if (timer == leaps[i].transition /* Exactly at the transition time.  */
-      && ((i == 0 && leaps[i].change > 0)
-	  || leaps[i].change > leaps[i - 1].change))
+      && (leaps[i].change > (i == 0 ? 0 : leaps[i - 1].change)))
     {
       *leap_hit = 1;
       while (i > 0