From 60067b5ae6fb7d8a714a99eac67432f2807df910 Mon Sep 17 00:00:00 2001 From: sebres Date: Thu, 31 Oct 2024 12:30:02 +0000 Subject: [PATCH 1/2] typo (zone name in errorcode) --- library/clock.tcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/clock.tcl b/library/clock.tcl index d65d9afed5e..bf697897409 100644 --- a/library/clock.tcl +++ b/library/clock.tcl @@ -3416,7 +3416,7 @@ proc ::tcl::clock::LoadTimeZoneFile { fileName } { if { [regexp {^[/\\]|^[a-zA-Z]+:|(?:^|[/\\])\.\.} $fileName] } { return -code error \ - -errorcode [list CLOCK badTimeZone $:fileName] \ + -errorcode [list CLOCK badTimeZone :$fileName] \ "time zone \":$fileName\" not valid" } if { [catch { From 19bb05e3eba205e319ef40800dc8b58ac269b2d2 Mon Sep 17 00:00:00 2001 From: sebres Date: Thu, 31 Oct 2024 13:21:49 +0000 Subject: [PATCH 2/2] more typos fixed, don't swallow real error message if read TZ fails, several fixed and normalizations, coverage for TZ-path safity check (path should not escape the given directory) --- library/clock.tcl | 41 ++++++++++++++++++++++++++++------------- tests/clock.test | 15 ++++++++++++--- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/library/clock.tcl b/library/clock.tcl index bf697897409..c64c4228a4d 100644 --- a/library/clock.tcl +++ b/library/clock.tcl @@ -3200,24 +3200,29 @@ proc ::tcl::clock::SetupTimeZone { timezone } { }] && [catch { LoadZoneinfoFile [string range $timezone 1 end] - }] + } ret opts] } { - return -code error \ - -errorcode [list CLOCK badTimeZone $timezone] \ - "time zone \"$timezone\" not found" + dict unset opts -errorinfo + if {[lindex [dict get $opts -errorcode] 0] ne "CLOCK"} { + dict set opts -errorcode [list CLOCK badTimeZone $timezone] + set ret "time zone \"$timezone\" not found: $ret" + } + return -options $opts $ret } } elseif { ![catch {ParsePosixTimeZone $timezone} tzfields] } { # This looks like a POSIX time zone - try to process it - if { [catch {ProcessPosixTimeZone $tzfields} data opts] } { - if { [lindex [dict get $opts -errorcode] 0] eq {CLOCK} } { - dict unset opts -errorinfo + if { [catch {ProcessPosixTimeZone $tzfields} ret opts] } { + dict unset opts -errorinfo + if {[lindex [dict get $opts -errorcode] 0] ne "CLOCK"} { + dict set opts -errorcode [list CLOCK badTimeZone $timezone] + set ret "time zone \"$timezone\" not found: $ret" } - return -options $opts $data + return -options $opts $ret } else { - set TZData($timezone) $data + set TZData($timezone) $ret } } else { @@ -3226,9 +3231,13 @@ proc ::tcl::clock::SetupTimeZone { timezone } { # again with a time zone file - this time without a colon if { [catch { LoadTimeZoneFile $timezone }] - && [catch { LoadZoneinfoFile $timezone } - opts] } { + && [catch { LoadZoneinfoFile $timezone } ret opts] } { dict unset opts -errorinfo - return -options $opts "time zone $timezone not found" + if {[lindex [dict get $opts -errorcode] 0] ne "CLOCK"} { + dict set opts -errorcode [list CLOCK badTimeZone $timezone] + set ret "time zone \"$timezone\" not found: $ret" + } + return -options $opts $ret } set TZData($timezone) $TZData(:$timezone) } @@ -3457,15 +3466,21 @@ proc ::tcl::clock::LoadZoneinfoFile { fileName } { if { [regexp {^[/\\]|^[a-zA-Z]+:|(?:^|[/\\])\.\.} $fileName] } { return -code error \ - -errorcode [list CLOCK badTimeZone $:fileName] \ + -errorcode [list CLOCK badTimeZone :$fileName] \ "time zone \":$fileName\" not valid" } + set fname "" foreach d $ZoneinfoPaths { set fname [file join $d $fileName] if { [file readable $fname] && [file isfile $fname] } { break } - unset fname + set fname "" + } + if {$fname eq ""} { + return -code error \ + -errorcode [list CLOCK badTimeZone :$fileName] \ + "time zone \":$fileName\" not found" } ReadZoneinfoFile $fileName $fname } diff --git a/tests/clock.test b/tests/clock.test index 4ad6c6dba0f..cb848be0981 100644 --- a/tests/clock.test +++ b/tests/clock.test @@ -280,9 +280,18 @@ test clock-1.4 "clock format - bad flag" {*}{ -result {1 {bad switch "-oops": must be -format, -gmt, -locale, or -timezone} {CLOCK badSwitch -oops}} } -test clock-1.5 "clock format - bad timezone" { - list [catch {clock format 0 -format "%s" -timezone :NOWHERE} msg] $msg $::errorCode -} {1 {time zone ":NOWHERE" not found} {CLOCK badTimeZone :NOWHERE}} +test clock-1.5 "clock format - bad timezone" -body { + clock format 0 -format "%s" -timezone :NOWHERE +} -returnCodes 1 -result {time zone ":NOWHERE" not found} -errorCode {CLOCK badTimeZone :NOWHERE} +foreach tz [list {*}{ + ../UNSAFEPATH/NOWHERE UNSAFEPATH/../GMT //UNSAFEPATH/NOWHERE + zipfs:/UNSAFEPATH/NOWHERE C:/UNSAFEPATH/NOWHERE + } [list $::tcl::clock::DataDir/GMT] +] { +test clock-1.5.1 "clock format - bad timezone" -body { + clock format 0 -format "%s" -timezone $tz +} -returnCodes 1 -result "time zone \":$tz\" not valid" -errorCode [list CLOCK badTimeZone :$tz] +} test clock-1.6 "clock format - gmt + timezone" { list [catch {clock format 0 -timezone :GMT -gmt true} msg] $msg $::errorCode