This is an automated email from the ASF dual-hosted git repository.

GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 3719146aed19bd6f5f6a001eead1324413ae78da
Author: yukangzhi <[email protected]>
AuthorDate: Mon Oct 26 15:06:25 2026 +0800

    libs/libc/time: initialize goback/goahead in tzparse().
    
    tzparse() only sets sp->goback/sp->goahead in the DST-rule branch; the
    standard-time-only branch and the early error returns leave them
    untouched. When tzparse() parses a TZ environment string it is called on
    a scratch state_s obtained from lib_malloc() (via zoneinit() from
    tzset()), which is not zeroed. Only tzload() cleared these fields, so
    the TZ-string path published uninitialized heap garbage into g_lcl_st.
    
    localsub() reads goback/goahead to decide whether to apply a time
    wrap-around, so a bogus value intermittently produces wrong time values
    (observed as sporadic failures in PSE52 time stress tests, e.g. mktime()
    off by 7h, localtime() off by 1h).
    
    Initialize both fields to FALSE unconditionally at tzparse() entry, so
    every branch leaves them in a defined state.
    
    Assisted-by: Kiro
    Signed-off-by: yukangzhi <[email protected]>
---
 libs/libc/time/lib_localtime.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/libs/libc/time/lib_localtime.c b/libs/libc/time/lib_localtime.c
index e2a6e8533c6..7f319df121e 100644
--- a/libs/libc/time/lib_localtime.c
+++ b/libs/libc/time/lib_localtime.c
@@ -1547,6 +1547,18 @@ static int tzparse(FAR const char *name, FAR struct 
state_s *sp,
   time_t atlo = TIME_T_MIN;
   time_t leaplo = TIME_T_MIN;
 
+  /* Initialize goback/goahead unconditionally. These are only set to TRUE
+   * in the DST-rule branch below, while the standard-time-only branch and
+   * the early error returns leave them untouched. tzparse() may be called
+   * on a scratch state_s obtained from lib_malloc() (e.g. via zoneinit()
+   * when parsing a TZ environment string) that is NOT zeroed, so without
+   * this they would carry uninitialized heap garbage. localsub() later
+   * reads them to decide whether to apply a time wrap-around, so a bogus
+   * value produces intermittent wrong time values.
+   */
+
+  sp->goback = sp->goahead = FALSE;
+
   stdname = name;
   if (*name == '<')
     {

Reply via email to