Git Product home page Git Product logo

tzdump's People

Contributors

alexandrebelloni avatar jmaggard10 avatar mcpat avatar roddehugo avatar

Stargazers

 avatar

Watchers

 avatar

tzdump's Issues

weekofmonth function gives incorrect week when day of month is multiple of 7

Seeing problem when running tzdump with timezones that have Daylight Savings Time. The output has the incorrect week of the month.

Example output for MST7MDT should have
MST7MDT,M3.2.0,M11.1.0

But output gives the following:
MST7MDT,M3.3.0,M11.1.0

Looking through the logic in the weekofmonth function, bolded line will give wrong week for multiples of 7 (i.e. March 7 or 14, November 7 or 14):
int weekofmonth(int mday, int wday)
{
int tmp;

TRACE(("weekofmonth(mday = %d, wday = %d)\n", mday, wday));

tmp = 1 + mday/7;
/* Assume that the last week of the month is desired. */
if ( tmp == 4 )
tmp++;

return tmp;
}

Verbose output running tzdump:
>tzdump -p . -v MST7MDT
ttisstdcnt = 4
leapcnt = 0
timecnt = 149
typecnt = 4
charcnt = 16
transit[0]: time=-1633273200 (Sun Mar 31 09:00:00 GMT 1918) type=0
transit[1]: time=-1615132800 (Sun Oct 27 08:00:00 GMT 1918) type=1
transit[2]: time=-1601823600 (Sun Mar 30 09:00:00 GMT 1919) type=0
transit[3]: time=-1583683200 (Sun Oct 26 08:00:00 GMT 1919) type=1
transit[4]: time=-880210800 (Mon Feb 09 09:00:00 GMT 1942) type=2
transit[5]: time=-769395600 (Tue Aug 14 23:00:00 GMT 1945) type=3
transit[6]: time=-765388800 (Sun Sep 30 08:00:00 GMT 1945) type=1
transit[7]: time=-84380400 (Sun Apr 30 09:00:00 GMT 1967) type=0
transit[8]: time=-68659200 (Sun Oct 29 08:00:00 GMT 1967) type=1
transit[9]: time=-52930800 (Sun Apr 28 09:00:00 GMT 1968) type=0
transit[10]: time=-37209600 (Sun Oct 27 08:00:00 GMT 1968) type=1
transit[11]: time=-21481200 (Sun Apr 27 09:00:00 GMT 1969) type=0
transit[12]: time=-5760000 (Sun Oct 26 08:00:00 GMT 1969) type=1
transit[13]: time=9968400 (Sun Apr 26 09:00:00 GMT 1970) type=0
transit[14]: time=25689600 (Sun Oct 25 08:00:00 GMT 1970) type=1
transit[15]: time=41418000 (Sun Apr 25 09:00:00 GMT 1971) type=0
transit[16]: time=57744000 (Sun Oct 31 08:00:00 GMT 1971) type=1
transit[17]: time=73472400 (Sun Apr 30 09:00:00 GMT 1972) type=0
transit[18]: time=89193600 (Sun Oct 29 08:00:00 GMT 1972) type=1
transit[19]: time=104922000 (Sun Apr 29 09:00:00 GMT 1973) type=0
transit[20]: time=120643200 (Sun Oct 28 08:00:00 GMT 1973) type=1
transit[21]: time=126694800 (Sun Jan 06 09:00:00 GMT 1974) type=0
transit[22]: time=152092800 (Sun Oct 27 08:00:00 GMT 1974) type=1
transit[23]: time=162378000 (Sun Feb 23 09:00:00 GMT 1975) type=0
transit[24]: time=183542400 (Sun Oct 26 08:00:00 GMT 1975) type=1
transit[25]: time=199270800 (Sun Apr 25 09:00:00 GMT 1976) type=0
transit[26]: time=215596800 (Sun Oct 31 08:00:00 GMT 1976) type=1
transit[27]: time=230720400 (Sun Apr 24 09:00:00 GMT 1977) type=0
transit[28]: time=247046400 (Sun Oct 30 08:00:00 GMT 1977) type=1
transit[29]: time=262774800 (Sun Apr 30 09:00:00 GMT 1978) type=0
transit[30]: time=278496000 (Sun Oct 29 08:00:00 GMT 1978) type=1
transit[31]: time=294224400 (Sun Apr 29 09:00:00 GMT 1979) type=0
transit[32]: time=309945600 (Sun Oct 28 08:00:00 GMT 1979) type=1
transit[33]: time=325674000 (Sun Apr 27 09:00:00 GMT 1980) type=0
transit[34]: time=341395200 (Sun Oct 26 08:00:00 GMT 1980) type=1
transit[35]: time=357123600 (Sun Apr 26 09:00:00 GMT 1981) type=0
transit[36]: time=372844800 (Sun Oct 25 08:00:00 GMT 1981) type=1
transit[37]: time=388573200 (Sun Apr 25 09:00:00 GMT 1982) type=0
transit[38]: time=404899200 (Sun Oct 31 08:00:00 GMT 1982) type=1
transit[39]: time=420022800 (Sun Apr 24 09:00:00 GMT 1983) type=0
transit[40]: time=436348800 (Sun Oct 30 08:00:00 GMT 1983) type=1
transit[41]: time=452077200 (Sun Apr 29 09:00:00 GMT 1984) type=0
transit[42]: time=467798400 (Sun Oct 28 08:00:00 GMT 1984) type=1
transit[43]: time=483526800 (Sun Apr 28 09:00:00 GMT 1985) type=0
transit[44]: time=499248000 (Sun Oct 27 08:00:00 GMT 1985) type=1
transit[45]: time=514976400 (Sun Apr 27 09:00:00 GMT 1986) type=0
transit[46]: time=530697600 (Sun Oct 26 08:00:00 GMT 1986) type=1
transit[47]: time=544611600 (Sun Apr 05 09:00:00 GMT 1987) type=0
transit[48]: time=562147200 (Sun Oct 25 08:00:00 GMT 1987) type=1
transit[49]: time=576061200 (Sun Apr 03 09:00:00 GMT 1988) type=0
transit[50]: time=594201600 (Sun Oct 30 08:00:00 GMT 1988) type=1
transit[51]: time=607510800 (Sun Apr 02 09:00:00 GMT 1989) type=0
transit[52]: time=625651200 (Sun Oct 29 08:00:00 GMT 1989) type=1
transit[53]: time=638960400 (Sun Apr 01 09:00:00 GMT 1990) type=0
transit[54]: time=657100800 (Sun Oct 28 08:00:00 GMT 1990) type=1
transit[55]: time=671014800 (Sun Apr 07 09:00:00 GMT 1991) type=0
transit[56]: time=688550400 (Sun Oct 27 08:00:00 GMT 1991) type=1
transit[57]: time=702464400 (Sun Apr 05 09:00:00 GMT 1992) type=0
transit[58]: time=720000000 (Sun Oct 25 08:00:00 GMT 1992) type=1
transit[59]: time=733914000 (Sun Apr 04 09:00:00 GMT 1993) type=0
transit[60]: time=752054400 (Sun Oct 31 08:00:00 GMT 1993) type=1
transit[61]: time=765363600 (Sun Apr 03 09:00:00 GMT 1994) type=0
transit[62]: time=783504000 (Sun Oct 30 08:00:00 GMT 1994) type=1
transit[63]: time=796813200 (Sun Apr 02 09:00:00 GMT 1995) type=0
transit[64]: time=814953600 (Sun Oct 29 08:00:00 GMT 1995) type=1
transit[65]: time=828867600 (Sun Apr 07 09:00:00 GMT 1996) type=0
transit[66]: time=846403200 (Sun Oct 27 08:00:00 GMT 1996) type=1
transit[67]: time=860317200 (Sun Apr 06 09:00:00 GMT 1997) type=0
transit[68]: time=877852800 (Sun Oct 26 08:00:00 GMT 1997) type=1
transit[69]: time=891766800 (Sun Apr 05 09:00:00 GMT 1998) type=0
transit[70]: time=909302400 (Sun Oct 25 08:00:00 GMT 1998) type=1
transit[71]: time=923216400 (Sun Apr 04 09:00:00 GMT 1999) type=0
transit[72]: time=941356800 (Sun Oct 31 08:00:00 GMT 1999) type=1
transit[73]: time=954666000 (Sun Apr 02 09:00:00 GMT 2000) type=0
transit[74]: time=972806400 (Sun Oct 29 08:00:00 GMT 2000) type=1
transit[75]: time=986115600 (Sun Apr 01 09:00:00 GMT 2001) type=0
transit[76]: time=1004256000 (Sun Oct 28 08:00:00 GMT 2001) type=1
transit[77]: time=1018170000 (Sun Apr 07 09:00:00 GMT 2002) type=0
transit[78]: time=1035705600 (Sun Oct 27 08:00:00 GMT 2002) type=1
transit[79]: time=1049619600 (Sun Apr 06 09:00:00 GMT 2003) type=0
transit[80]: time=1067155200 (Sun Oct 26 08:00:00 GMT 2003) type=1
transit[81]: time=1081069200 (Sun Apr 04 09:00:00 GMT 2004) type=0
transit[82]: time=1099209600 (Sun Oct 31 08:00:00 GMT 2004) type=1
transit[83]: time=1112518800 (Sun Apr 03 09:00:00 GMT 2005) type=0
transit[84]: time=1130659200 (Sun Oct 30 08:00:00 GMT 2005) type=1
transit[85]: time=1143968400 (Sun Apr 02 09:00:00 GMT 2006) type=0
transit[86]: time=1162108800 (Sun Oct 29 08:00:00 GMT 2006) type=1
transit[87]: time=1173603600 (Sun Mar 11 09:00:00 GMT 2007) type=0
transit[88]: time=1194163200 (Sun Nov 04 08:00:00 GMT 2007) type=1
transit[89]: time=1205053200 (Sun Mar 09 09:00:00 GMT 2008) type=0
transit[90]: time=1225612800 (Sun Nov 02 08:00:00 GMT 2008) type=1
transit[91]: time=1236502800 (Sun Mar 08 09:00:00 GMT 2009) type=0
transit[92]: time=1257062400 (Sun Nov 01 08:00:00 GMT 2009) type=1
transit[93]: time=1268557200 (Sun Mar 14 09:00:00 GMT 2010) type=0
transit[94]: time=1289116800 (Sun Nov 07 08:00:00 GMT 2010) type=1
transit[95]: time=1300006800 (Sun Mar 13 09:00:00 GMT 2011) type=0
transit[96]: time=1320566400 (Sun Nov 06 08:00:00 GMT 2011) type=1
transit[97]: time=1331456400 (Sun Mar 11 09:00:00 GMT 2012) type=0
transit[98]: time=1352016000 (Sun Nov 04 08:00:00 GMT 2012) type=1
transit[99]: time=1362906000 (Sun Mar 10 09:00:00 GMT 2013) type=0
transit[100]: time=1383465600 (Sun Nov 03 08:00:00 GMT 2013) type=1
transit[101]: time=1394355600 (Sun Mar 09 09:00:00 GMT 2014) type=0
transit[102]: time=1414915200 (Sun Nov 02 08:00:00 GMT 2014) type=1
transit[103]: time=1425805200 (Sun Mar 08 09:00:00 GMT 2015) type=0
transit[104]: time=1446364800 (Sun Nov 01 08:00:00 GMT 2015) type=1
transit[105]: time=1457859600 (Sun Mar 13 09:00:00 GMT 2016) type=0
transit[106]: time=1478419200 (Sun Nov 06 08:00:00 GMT 2016) type=1
transit[107]: time=1489309200 (Sun Mar 12 09:00:00 GMT 2017) type=0
transit[108]: time=1509868800 (Sun Nov 05 08:00:00 GMT 2017) type=1
transit[109]: time=1520758800 (Sun Mar 11 09:00:00 GMT 2018) type=0
transit[110]: time=1541318400 (Sun Nov 04 08:00:00 GMT 2018) type=1
transit[111]: time=1552208400 (Sun Mar 10 09:00:00 GMT 2019) type=0
transit[112]: time=1572768000 (Sun Nov 03 08:00:00 GMT 2019) type=1
transit[113]: time=1583658000 (Sun Mar 08 09:00:00 GMT 2020) type=0
transit[114]: time=1604217600 (Sun Nov 01 08:00:00 GMT 2020) type=1
transit[115]: time=1615712400 (Sun Mar 14 09:00:00 GMT 2021) type=0
transit[116]: time=1636272000 (Sun Nov 07 08:00:00 GMT 2021) type=1
transit[117]: time=1647162000 (Sun Mar 13 09:00:00 GMT 2022) type=0
transit[118]: time=1667721600 (Sun Nov 06 08:00:00 GMT 2022) type=1
transit[119]: time=1678611600 (Sun Mar 12 09:00:00 GMT 2023) type=0
transit[120]: time=1699171200 (Sun Nov 05 08:00:00 GMT 2023) type=1
transit[121]: time=1710061200 (Sun Mar 10 09:00:00 GMT 2024) type=0
transit[122]: time=1730620800 (Sun Nov 03 08:00:00 GMT 2024) type=1
transit[123]: time=1741510800 (Sun Mar 09 09:00:00 GMT 2025) type=0
transit[124]: time=1762070400 (Sun Nov 02 08:00:00 GMT 2025) type=1
transit[125]: time=1772960400 (Sun Mar 08 09:00:00 GMT 2026) type=0
transit[126]: time=1793520000 (Sun Nov 01 08:00:00 GMT 2026) type=1
transit[127]: time=1805014800 (Sun Mar 14 09:00:00 GMT 2027) type=0
transit[128]: time=1825574400 (Sun Nov 07 08:00:00 GMT 2027) type=1
transit[129]: time=1836464400 (Sun Mar 12 09:00:00 GMT 2028) type=0
transit[130]: time=1857024000 (Sun Nov 05 08:00:00 GMT 2028) type=1
transit[131]: time=1867914000 (Sun Mar 11 09:00:00 GMT 2029) type=0
transit[132]: time=1888473600 (Sun Nov 04 08:00:00 GMT 2029) type=1
transit[133]: time=1899363600 (Sun Mar 10 09:00:00 GMT 2030) type=0
transit[134]: time=1919923200 (Sun Nov 03 08:00:00 GMT 2030) type=1
transit[135]: time=1930813200 (Sun Mar 09 09:00:00 GMT 2031) type=0
transit[136]: time=1951372800 (Sun Nov 02 08:00:00 GMT 2031) type=1
transit[137]: time=1962867600 (Sun Mar 14 09:00:00 GMT 2032) type=0
transit[138]: time=1983427200 (Sun Nov 07 08:00:00 GMT 2032) type=1
transit[139]: time=1994317200 (Sun Mar 13 09:00:00 GMT 2033) type=0
transit[140]: time=2014876800 (Sun Nov 06 08:00:00 GMT 2033) type=1
transit[141]: time=2025766800 (Sun Mar 12 09:00:00 GMT 2034) type=0
transit[142]: time=2046326400 (Sun Nov 05 08:00:00 GMT 2034) type=1
transit[143]: time=2057216400 (Sun Mar 11 09:00:00 GMT 2035) type=0
transit[144]: time=2077776000 (Sun Nov 04 08:00:00 GMT 2035) type=1
transit[145]: time=2088666000 (Sun Mar 09 09:00:00 GMT 2036) type=0
transit[146]: time=2109225600 (Sun Nov 02 08:00:00 GMT 2036) type=1
transit[147]: time=2120115600 (Sun Mar 08 09:00:00 GMT 2037) type=0
transit[148]: time=2140675200 (Sun Nov 01 08:00:00 GMT 2037) type=1
chars[0] = 'M'
chars[1] = 'D'
chars[2] = 'T'
chars[3] = 0
chars[4] = 'M'
chars[5] = 'S'
chars[6] = 'T'
chars[7] = 0
chars[8] = 'M'
chars[9] = 'W'
chars[10] = 'T'
chars[11] = 0
chars[12] = 'M'
chars[13] = 'P'
chars[14] = 'T'
chars[15] = 0
lti[0]: gmtoffset=-21600 isdst=1 abbrind=0 stds=0
lti[1]: gmtoffset=-25200 isdst=0 abbrind=4 stds=0
lti[2]: gmtoffset=-21600 isdst=1 abbrind=8 stds=0
lti[3]: gmtoffset=-21600 isdst=1 abbrind=12 stds=1
tt[0]: time=1604217600 (Sun Nov 01 08:00:00 GMT 2020) index=114 type=1
tt[1]: time=1615712400 (Sun Mar 14 09:00:00 GMT 2021) index=115 type=0
# MST7MDT
MST7MDT,M3.3.0,M11.1.0

Inconsistent POSIX TZ string returned by tzdump depending of time machine

Hello,

I found a problem with tzdump program. The TZ string returned by tzdump can be different depending if the machine time is in DST or not.

For instance, with America/Iqaluit timezone and tzdata-2021a, tzdump gives me for today, nov 9:

$ date
Wed 09 Nov 2022 10:49:45 AM CET
$ tzdump -q -p . America/Iqaluit
# America/Iqaluit
EST5EDT,M3.2.0,M11.1.0

But if I change my machine time to be 1 september (the point here is to switch to daylight saving time on the machine), tzdump gives me an another TZ POSIX string:

$ sudo date -s "1 SEP 2022 11:00:00"
$ date
Thu 01 Sep 2022 11:02:23 AM CEST
$ tzdump -q -p . America/Iqaluit
# America/Iqaluit
EST5EDT,M3.2.0/3,M11.1.0

Several timezones give different TZ strings depending of the machine time (Iqaluit, Troll, Gaza, Hebron, ...), not all timezones contained in the tz database.

The gcc compiler issues the following warnings.

The gcc compiler issues the following warnings:

tzdump.c: In function 'dumptzdata':
tzdump.c:486:37: warning: format '%d' expects argument of type 'int', but argument 3 has type 'long int' [-Wformat=]
    (void)printf("transit[%d]: time=%d (%s) type=%d\n",
                                    ~^
                                    %ld
     i, transit[i].time, ctimeGMT(transit[i].time),
        ~~~~~~~~~~~~~~~               
tzdump.c:486:50: warning: format '%d' expects argument of type 'int', but argument 5 has type 'long int' [-Wformat=]
    (void)printf("transit[%d]: time=%d (%s) type=%d\n",
                                                 ~^
                                                 %ld
tzdump.c:488:5:
     transit[i].type);
     ~~~~~~~~~~~~~~~                               
tzdump.c:503:9: warning: implicit declaration of function 'isprint' [-Wimplicit-function-declaration]
    if ( isprint(chars[i]) )
         ^~~~~~~
tzdump.c:518:38: warning: format '%d' expects argument of type 'int', but argument 3 has type 'time_t {aka long int}' [-Wformat=]
    (void)printf("leaps[%d]: transit=%d correct=%d\n",
                                     ~^
                                     %ld
      i, leaps[i].transit, leaps[i].correct);
         ~~~~~~~~~~~~~~~~              
tzdump.c:518:49: warning: format '%d' expects argument of type 'int', but argument 4 has type 'long int' [-Wformat=]
    (void)printf("leaps[%d]: transit=%d correct=%d\n",
                                                ~^
                                                %ld
      i, leaps[i].transit, leaps[i].correct);
                           ~~~~~~~~~~~~~~~~       
tzdump.c:626:30: warning: format '%d' expects argument of type 'int', but argument 2 has type 'time_t {aka long int}' [-Wformat=]
   (void)printf("tt[0]: time=%d (%s) index=%d type=%d\n",
                             ~^
                             %ld
     tt[0].time, ctimeGMT(tt[0].time),
     ~~~~~~~~~~                
tzdump.c:629:30: warning: format '%d' expects argument of type 'int', but argument 2 has type 'time_t {aka long int}' [-Wformat=]
   (void)printf("tt[1]: time=%d (%s) index=%d type=%d\n",
                             ~^
                             %ld
     tt[1].time, ctimeGMT(tt[1].time),
     ~~~~~~~~~~  

Version compiler:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.4.0-1ubuntu1_18.04.1' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04.1)

PR #10 faulty

Supersedes issue #7

The patch provided in #10 silences various warnings but fixes neither the underlying buffer-overrun vulnerability with strncat, nor the lack of a portable xxprintf format specifier for time_t.

The standard C strncat function is widely regarded as so badly flawed as to be useless, because its limit parameter does not reflect the overall size of the target buffer, but rather the space remaining in that buffer after the length of its current content is taken into account. Even when provided with a correct limit value, its safeguard is to truncate the string, resulting in an incorrect value which is useless for the purpose of this program.

To be fair, the limits provided are very generous, so one needs to go to extreme lengths to broach them, but this command demonstrates how the stack can be corrupted, causing an abort when it attempts to return from dumptzdata (back to main):

z=/./././.  # length 8
z=$z$z$z$z  # length 32
z=$z$z$z$z  # length 128
z=$z$z$z$z  # length 512
z=$z$z$z$z  # length 2048 
./tzdump -p /usr/share/zoneinfo$z .$z$z$z$z/PST8PDT

More broadly, return values that indicate potential errors should be checked, not simply cast away with (void).

Where is tzfile.h ?

gcc tzdump.c -o tzdump
tzdump.c:50:20: fatal error: tzfile.h: No such file or directory
 #include "tzfile.h"
                    ^
compilation terminated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.