You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by jo...@apache.org on 2004/03/25 23:29:35 UTC

cvs commit: apr/time/win32 time.c

jorton      2004/03/25 14:29:35

  Modified:    .        Tag: APR_0_9_BRANCH CHANGES
               test     Tag: APR_0_9_BRANCH testtime.c
               time/unix Tag: APR_0_9_BRANCH time.c
               time/win32 Tag: APR_0_9_BRANCH time.c
  Log:
  * time/unix/time.c (apr_time_exp_get): Remove year check that failed for
    2038, use apr_time_t to avoid overflow.
  
  * time/win32/time.c (apr_time_exp_get): ditto
  
  * test/testtime.c (test_2038): Add regression test.
  
  Submitted by: Philip Martin <ph...@codematters.co.uk>
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.426.2.13 +3 -0      apr/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apr/CHANGES,v
  retrieving revision 1.426.2.12
  retrieving revision 1.426.2.13
  diff -w -d -u -r1.426.2.12 -r1.426.2.13
  --- CHANGES	24 Mar 2004 20:09:18 -0000	1.426.2.12
  +++ CHANGES	25 Mar 2004 22:29:35 -0000	1.426.2.13
  @@ -1,5 +1,8 @@
   Changes with APR 0.9.5
   
  +  *) Fix apr_time_exp_get() for dates in 2038.  
  +     [Philip Martin <philip codematters.co.uk>]
  +
     *) Add APR_LARGEFILE flag to allow opening files with the
        O_LARGEFILE flag; not recommended for general use, see
        include/apr_file_io.h.  [Joe Orton]
  
  
  
  No                   revision
  No                   revision
  1.49.2.3  +19 -0     apr/test/testtime.c
  
  Index: testtime.c
  ===================================================================
  RCS file: /home/cvs/apr/test/testtime.c,v
  retrieving revision 1.49.2.2
  retrieving revision 1.49.2.3
  diff -w -d -u -r1.49.2.2 -r1.49.2.3
  --- testtime.c	13 Feb 2004 09:33:52 -0000	1.49.2.2
  +++ testtime.c	25 Mar 2004 22:29:35 -0000	1.49.2.3
  @@ -265,6 +265,24 @@
       CuAssertTrue(tc, rv == APR_SUCCESS);
   }
   
  +/* 0.9.4 and earlier rejected valid dates in 2038 */
  +static void test_2038(CuTest *tc)
  +{
  +    apr_time_exp_t xt;
  +    apr_time_t t;
  +
  +    /* 2038-01-19T03:14:07.000000Z */
  +    xt.tm_year = 138;
  +    xt.tm_mon = 0;
  +    xt.tm_mday = 19;
  +    xt.tm_hour = 3;
  +    xt.tm_min = 14;
  +    xt.tm_sec = 7;
  +    
  +    apr_assert_success(tc, "explode January 19th, 2038",
  +                       apr_time_exp_get(&t, &xt));
  +}
  +
   CuSuite *testtime(void)
   {
       CuSuite *suite = CuSuiteNew("Time");
  @@ -281,6 +299,7 @@
       SUITE_ADD_TEST(suite, test_strftimesmall);
       SUITE_ADD_TEST(suite, test_exp_tz);
       SUITE_ADD_TEST(suite, test_strftimeoffset);
  +    SUITE_ADD_TEST(suite, test_2038);
   
       return suite;
   }
  
  
  
  No                   revision
  No                   revision
  1.73.2.2  +2 -7      apr/time/unix/time.c
  
  Index: time.c
  ===================================================================
  RCS file: /home/cvs/apr/time/unix/time.c,v
  retrieving revision 1.73.2.1
  retrieving revision 1.73.2.2
  diff -w -d -u -r1.73.2.1 -r1.73.2.2
  --- time.c	13 Feb 2004 09:33:55 -0000	1.73.2.1
  +++ time.c	25 Mar 2004 22:29:35 -0000	1.73.2.2
  @@ -135,15 +135,10 @@
   
   APR_DECLARE(apr_status_t) apr_time_exp_get(apr_time_t *t, apr_time_exp_t *xt)
   {
  -    int year;
  -    time_t days;
  +    apr_time_t year = xt->tm_year;
  +    apr_time_t days;
       static const int dayoffset[12] =
       {306, 337, 0, 31, 61, 92, 122, 153, 184, 214, 245, 275};
  -
  -    year = xt->tm_year;
  -    if (year < 70 || ((sizeof(time_t) <= 4) && (year >= 138))) {
  -        return APR_EBADDATE;
  -    }
   
       /* shift new year to 1st March in order to make leap year calc easy */
   
  
  
  
  No                   revision
  No                   revision
  1.46.2.2  +2 -8      apr/time/win32/time.c
  
  Index: time.c
  ===================================================================
  RCS file: /home/cvs/apr/time/win32/time.c,v
  retrieving revision 1.46.2.1
  retrieving revision 1.46.2.2
  diff -w -d -u -r1.46.2.1 -r1.46.2.2
  --- time.c	13 Feb 2004 09:33:55 -0000	1.46.2.1
  +++ time.c	25 Mar 2004 22:29:35 -0000	1.46.2.2
  @@ -218,16 +218,10 @@
   APR_DECLARE(apr_status_t) apr_time_exp_get(apr_time_t *t,
                                              apr_time_exp_t *xt)
   {
  -    int year;
  -    time_t days;
  +    apr_time_t year = xt->tm_year;
  +    apr_time_t days;
       static const int dayoffset[12] =
       {306, 337, 0, 31, 61, 92, 122, 153, 184, 214, 245, 275};
  -
  -    year = xt->tm_year;
  -
  -    if (year < 70 || ((sizeof(time_t) <= 4) && (year >= 138))) {
  -        return APR_EBADDATE;
  -    }
   
       /* shift new year to 1st March in order to make leap year calc easy */