gdatetime: Disallow NAN as a number of seconds in a GDateTime

The fiendish thing about NAN is that it never compares TRUE against
anything, so the limit checks `seconds < 0.0 || seconds >= 60.0` were
never triggering.

oss-fuzz#28473

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
This commit is contained in:
Philip Withnall
2020-12-09 14:50:02 +00:00
parent 737a853f8d
commit c3805d74ba
2 changed files with 16 additions and 1 deletions

View File

@@ -18,6 +18,7 @@
#include "config.h"
#include <math.h>
#include <string.h>
#include <time.h>
#include <gi18n.h>
@@ -799,6 +800,12 @@ test_GDateTime_new_from_iso8601 (void)
/* Timezone hours two digits */
dt = g_date_time_new_from_iso8601 ("2016-08-24T22-2Z", NULL);
g_assert_null (dt);
/* Ordinal date (YYYYDDD), space separator, and then time as HHMMSS,SSS
* The interesting bit is that the seconds field is so long as to parse as
* NaN */
dt = g_date_time_new_from_iso8601 ("0005306 000001,666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666600080000-00", NULL);
g_assert_null (dt);
}
typedef struct {
@@ -1273,6 +1280,8 @@ test_GDateTime_new_full (void)
g_date_time_unref (dt);
dt = g_date_time_new_utc (2016, 12, 32, 22, 10, 42);
g_assert_null (dt);
dt = g_date_time_new_utc (2020, 12, 9, 14, 49, NAN);
g_assert_null (dt);
}
static void