diff options
author | Jim Meyering <meyering@redhat.com> | 2012-07-04 12:58:07 +0200 |
---|---|---|
committer | Jim Meyering <meyering@redhat.com> | 2012-07-04 12:58:07 +0200 |
commit | d8f90adf5f01512958b6da46bd5eea01294a434e (patch) | |
tree | a893b72d7893ad2b063b9be0a2774d6ff8ba0679 /lib/parse-datetime.y | |
parent | d0ea2a12f6fb377f930886d404f3dfc2a732537d (diff) | |
download | gnulib-d8f90adf5f01512958b6da46bd5eea01294a434e.tar.gz |
parse-datetime: fix failure to diagnose invalid input
date -d "$(printf '\xb0')" would print 00:00:00 with today's date
rather than diagnosing the invalid input. Now it reports this:
date: invalid date '\260'
* lib/parse-datetime.y (to_uchar): Define.
(yylex): Don't sign-extend "other" bytes.
* m4/parse-datetime.m4: Require AC_C_INLINE for first use of "inline".
Thanks to Bruno Haible for the patch to this file.
* tests/test-parse-datetime.c (main): Add a test to trigger the bug.
Peter Evans reported the bug in GNU date: http://bugs.gnu.org/11843
Diffstat (limited to 'lib/parse-datetime.y')
-rw-r--r-- | lib/parse-datetime.y | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/parse-datetime.y b/lib/parse-datetime.y index 67669f6319..4d9f65ab2d 100644 --- a/lib/parse-datetime.y +++ b/lib/parse-datetime.y @@ -113,6 +113,11 @@ typedef long int long_time_t; typedef time_t long_time_t; #endif +/* Convert a possibly-signed character to an unsigned character. This is + a bit safer than casting to unsigned char, since it catches some type + errors that the cast doesn't. */ +static inline unsigned char to_uchar (char ch) { return ch; } + /* Lots of this code assumes time_t and time_t-like values fit into long_time_t. */ verify (TYPE_MINIMUM (long_time_t) <= TYPE_MINIMUM (time_t) @@ -1171,7 +1176,8 @@ yylex (YYSTYPE *lvalp, parser_control *pc) } if (c != '(') - return *pc->input++; + return to_uchar (*pc->input++); + count = 0; do { |