emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r117637: Don't mishandle year-9999 dates.


From: Paul Eggert
Subject: [Emacs-diffs] trunk r117637: Don't mishandle year-9999 dates.
Date: Sun, 03 Aug 2014 15:39:01 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 117637
revision-id: address@hidden
parent: address@hidden
fixes bug: http://debbugs.gnu.org/18176
committer: Paul Eggert <address@hidden>
branch nick: trunk
timestamp: Sun 2014-08-03 08:38:52 -0700
message:
  Don't mishandle year-9999 dates.
  
  * lisp/calendar/parse-time.el (parse-time-rules):
  Allow years up to most-positive-fixnum.
  * lisp/calendar/time-date.el (date-to-time):
  Pass "Specified time is not representable" errors through.
  * lisp/url/url-cookie.el (url-cookie-expired-p): Treat out-of-range
  expiration dates as if they were far in the future.
  * src/editfns.c (decode_time_components): Store an invalid timespec
  on overflow, instead of returning false, so that the caller can
  distinguish overflow from other errors.
  (lisp_time_argument, lisp_seconds_argument): If the time is out
  of range, signal a time overflow instead of an invalid time spec.
  * src/keyboard.c (decode_timer): Treat time overflow like other
  timespec errors.
modified:
  lisp/ChangeLog                 changelog-20091113204419-o5vbwnq5f7feedwu-1432
  lisp/calendar/parse-time.el    
parsetime.el-20091113204419-o5vbwnq5f7feedwu-2379
  lisp/calendar/time-date.el     
timedate.el-20091113204419-o5vbwnq5f7feedwu-2380
  lisp/url/ChangeLog             changelog-20091113204419-o5vbwnq5f7feedwu-3116
  lisp/url/url-cookie.el         
urlcookie.el-20091113204419-o5vbwnq5f7feedwu-2980
  src/ChangeLog                  changelog-20091113204419-o5vbwnq5f7feedwu-1438
  src/editfns.c                  editfns.c-20091113204419-o5vbwnq5f7feedwu-255
  src/keyboard.c                 keyboard.c-20091113204419-o5vbwnq5f7feedwu-449
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2014-08-02 22:52:55 +0000
+++ b/lisp/ChangeLog    2014-08-03 15:38:52 +0000
@@ -1,3 +1,11 @@
+2014-08-03  Paul Eggert  <address@hidden>
+
+       Don't mishandle year-9999 dates (Bug#18176).
+       * calendar/parse-time.el (parse-time-rules):
+       Allow years up to most-positive-fixnum.
+       * calendar/time-date.el (date-to-time):
+       Pass "Specified time is not representable" errors through.
+
 2014-08-02  Fabián Ezequiel Gallina  <address@hidden>
 
        * progmodes/python.el: Completion code cleanups.

=== modified file 'lisp/calendar/parse-time.el'
--- a/lisp/calendar/parse-time.el       2014-03-23 23:14:52 +0000
+++ b/lisp/calendar/parse-time.el       2014-08-03 15:38:52 +0000
@@ -131,7 +131,7 @@
   `(((6) parse-time-weekdays)
     ((3) (1 31))
     ((4) parse-time-months)
-    ((5) (100 4038))
+    ((5) (100 ,most-positive-fixnum))
     ((2 1 0)
      ,#'(lambda () (and (stringp parse-time-elt)
                        (= (length parse-time-elt) 8)

=== modified file 'lisp/calendar/time-date.el'
--- a/lisp/calendar/time-date.el        2014-05-12 23:56:22 +0000
+++ b/lisp/calendar/time-date.el        2014-08-03 15:38:52 +0000
@@ -119,13 +119,20 @@
 (defun date-to-time (date)
   "Parse a string DATE that represents a date-time and return a time value.
 If DATE lacks timezone information, GMT is assumed."
-  (condition-case ()
+  (condition-case err
       (apply 'encode-time (parse-time-string date))
-    (error (condition-case ()
-              (apply 'encode-time
-                     (parse-time-string
-                      (timezone-make-date-arpa-standard date)))
-            (error (error "Invalid date: %s" date))))))
+    (error
+     (let ((overflow-error '(error "Specified time is not representable")))
+       (if (equal err overflow-error)
+          (apply 'signal err)
+        (condition-case err
+            (apply 'encode-time
+                   (parse-time-string
+                    (timezone-make-date-arpa-standard date)))
+          (error
+           (if (equal err overflow-error)
+               (apply 'signal err)
+             (error "Invalid date: %s" date)))))))))
 
 ;; Bit of a mess.  Emacs has float-time since at least 21.1.
 ;; This file is synced to Gnus, and XEmacs packages may have been written

=== modified file 'lisp/url/ChangeLog'
--- a/lisp/url/ChangeLog        2014-06-26 06:55:15 +0000
+++ b/lisp/url/ChangeLog        2014-08-03 15:38:52 +0000
@@ -1,3 +1,9 @@
+2014-08-03  Paul Eggert  <address@hidden>
+
+       Don't mishandle dates in the year 9999 (Bug#18176).
+       * url-cookie.el (url-cookie-expired-p): Treat out-of-range
+       expiration dates as if they were far in the future.
+
 2014-06-26  Leo Liu  <address@hidden>
 
        * url-http.el (url-http-end-of-headers): Remove duplicate defvar.

=== modified file 'lisp/url/url-cookie.el'
--- a/lisp/url/url-cookie.el    2014-02-05 07:46:40 +0000
+++ b/lisp/url/url-cookie.el    2014-08-03 15:38:52 +0000
@@ -158,7 +158,9 @@
   "Return non-nil if COOKIE is expired."
   (let ((exp (url-cookie-expires cookie)))
     (and (> (length exp) 0)
-        (> (float-time) (float-time (date-to-time exp))))))
+        (condition-case ()
+            (> (float-time) (float-time (date-to-time exp)))
+          (error nil)))))
 
 (defun url-cookie-retrieve (host &optional localpart secure)
   "Retrieve all cookies for a specified HOST and LOCALPART."

=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2014-08-03 12:34:44 +0000
+++ b/src/ChangeLog     2014-08-03 15:38:52 +0000
@@ -1,5 +1,14 @@
 2014-08-03  Paul Eggert  <address@hidden>
 
+       Don't mishandle year-9999 dates (Bug#18176).
+       * editfns.c (decode_time_components): Store an invalid timespec
+       on overflow, instead of returning false, so that the caller can
+       distinguish overflow from other errors.
+       (lisp_time_argument, lisp_seconds_argument): If the time is out
+       of range, signal a time overflow instead of an invalid time spec.
+       * keyboard.c (decode_timer): Treat time overflow like other
+       timespec errors.
+
        Avoid undefined behavior with signed left shift.
        Caught by 'gcc -fsanitize=undefined'.
        * dispextern.h, scroll.c (scrolling_max_lines_saved, scrolling_1):

=== modified file 'src/editfns.c'
--- a/src/editfns.c     2014-06-23 04:11:29 +0000
+++ b/src/editfns.c     2014-08-03 15:38:52 +0000
@@ -1516,7 +1516,8 @@
    list, generate the corresponding time value.
 
    If RESULT is not null, store into *RESULT the converted time;
-   this can fail if the converted time does not fit into struct timespec.
+   if the converted time does not fit into struct timespec,
+   store an invalid timespec to indicate the overflow.
    If *DRESULT is not null, store into *DRESULT the number of
    seconds since the start of the POSIX Epoch.
 
@@ -1529,7 +1530,7 @@
   EMACS_INT hi, lo, us, ps;
   if (! (INTEGERP (high) && INTEGERP (low)
         && INTEGERP (usec) && INTEGERP (psec)))
-    return 0;
+    return false;
   hi = XINT (high);
   lo = XINT (low);
   us = XINT (usec);
@@ -1555,16 +1556,13 @@
          *result = make_timespec ((sec << 16) + lo, us * 1000 + ps / 1000);
        }
       else
-       {
-         /* Overflow in the highest-order component.  */
-         return 0;
-       }
+       *result = invalid_timespec ();
     }
 
   if (dresult)
     *dresult = (us * 1e6 + ps) / 1e12 + lo + hi * 65536.0;
 
-  return 1;
+  return true;
 }
 
 /* Decode a Lisp list SPECIFIED_TIME that represents a time.
@@ -1576,22 +1574,23 @@
 struct timespec
 lisp_time_argument (Lisp_Object specified_time)
 {
-  struct timespec t;
   if (NILP (specified_time))
-    t = current_timespec ();
+    return current_timespec ();
   else
     {
       Lisp_Object high, low, usec, psec;
+      struct timespec t;
       if (! (disassemble_lisp_time (specified_time, &high, &low, &usec, &psec)
             && decode_time_components (high, low, usec, psec, &t, 0)))
        error ("Invalid time specification");
+      if (! timespec_valid_p (t))
+       time_overflow ();
+      return t;
     }
-  return t;
 }
 
 /* Like lisp_time_argument, except decode only the seconds part,
-   do not allow out-of-range time stamps, do not check the subseconds part,
-   and always round down.  */
+   and do not check the subseconds part.  */
 static time_t
 lisp_seconds_argument (Lisp_Object specified_time)
 {
@@ -1605,6 +1604,8 @@
             && decode_time_components (high, low, make_number (0),
                                        make_number (0), &t, 0)))
        error ("Invalid time specification");
+      if (! timespec_valid_p (t))
+       time_overflow ();
       return t.tv_sec;
     }
 }

=== modified file 'src/keyboard.c'
--- a/src/keyboard.c    2014-08-01 15:12:01 +0000
+++ b/src/keyboard.c    2014-08-03 15:38:52 +0000
@@ -4370,8 +4370,9 @@
   if (! NILP (vector[0]))
     return 0;
 
-  return decode_time_components (vector[1], vector[2], vector[3], vector[8],
-                                result, 0);
+  return (decode_time_components (vector[1], vector[2], vector[3], vector[8],
+                                 result, 0)
+         && timespec_valid_p (*result));
 }
 
 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]