This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit d1c61da8a259b9dde6e94d1af9799092beb6e7c0 Author: pangzhen1 <[email protected]> AuthorDate: Tue Jul 28 18:28:17 2026 +0800 libc/time: Preserve the abbreviation characters of the TZ string. zoneinit() called scrub_abbrs() unconditionally on both the tzload() path (zoneinfo binary file) and the tzparse() path (TZ environment string). scrub_abbrs() replaces any character not in TZ_ABBR_CHAR_SET with '_', which is correct defense for untrusted tzfile data but wrong for the TZ string: POSIX (PSE52 legacy mode) allows a wider character set in unquoted zone names (e.g. ! # $ % / ; = >). For TZ="!!!0", tzparse() writes "!!!" into sp->chars, then scrub_abbrs() turns it into "___", so mktime()/tzname report the wrong standard timezone name (PSE52 mktime TP18). Only scrub on the tzload() path; preserve original characters on the tzparse() path. The tzload() defense is unchanged, and tzparse()'s internal tzload(TZDEFRULES) writes to sp->chars beyond the std/dst name region that settzname() never indexes, so not scrubbing it is safe. Signed-off-by: pangzhen1 <[email protected]> Signed-off-by: ganjing <[email protected]> --- libs/libc/time/lib_localtime.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/libs/libc/time/lib_localtime.c b/libs/libc/time/lib_localtime.c index e1278c4f12d..ba18ee41c26 100644 --- a/libs/libc/time/lib_localtime.c +++ b/libs/libc/time/lib_localtime.c @@ -2850,16 +2850,26 @@ static int zoneinit(FAR const char *name) int err; err = tzload(name, g_lcl_ptr, TRUE); - if (err != 0 && name != NULL && name[0] != ':' && - tzparse(name, g_lcl_ptr, NULL) == 0) - { - err = 0; - } - if (err == 0) { + /* Data came from a zoneinfo binary file: scrub bogus abbreviation + * characters that could originate from an untrusted file. + */ + scrub_abbrs(g_lcl_ptr); } + else if (name != NULL && name[0] != ':' && + tzparse(name, g_lcl_ptr, NULL) == 0) + { + /* Data came from the TZ environment string. POSIX allows a wider + * character set (e.g. ! # $ % / ; = >) in unquoted zone names + * than TZ_ABBR_CHAR_SET permits, so preserve the original chars + * instead of scrubbing them (otherwise mktime()/tzname report + * "___" for inputs like TZ="!!!0"). + */ + + err = 0; + } return err; }
