From 20660bc0d78be82526486b58c2c049f0ab469164 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Tue, 23 Apr 2024 09:03:07 -0500 Subject: [PATCH] Adding more tests for invalid dates --- .../org/eclipse/jetty/http/HttpDateTime.java | 16 ++++++++++++---- .../org/eclipse/jetty/http/HttpDateTimeTest.java | 1 + 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/HttpDateTime.java b/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/HttpDateTime.java index 74a48f37f250..70b503dc3d59 100644 --- a/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/HttpDateTime.java +++ b/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/HttpDateTime.java @@ -14,6 +14,7 @@ package org.eclipse.jetty.http; import java.nio.charset.StandardCharsets; +import java.time.DateTimeException; import java.time.ZoneId; import java.time.ZoneOffset; import java.time.ZonedDateTime; @@ -219,11 +220,18 @@ else if (token.length() == 4) throw new IllegalArgumentException("Invalid [second]: " + datetime); // RFC 6265 - Section 5.1.1 - Step 6 - ZonedDateTime dateTime = ZonedDateTime.of(year, - month, day, hour, minute, second, 0, UTC); + try + { + ZonedDateTime dateTime = ZonedDateTime.of(year, + month, day, hour, minute, second, 0, UTC); - // RFC 6265 - Section 5.1.1 - Step 7 - return dateTime; + // RFC 6265 - Section 5.1.1 - Step 7 + return dateTime; + } + catch (DateTimeException e) + { + throw new IllegalArgumentException("Invalid date/time: " + datetime, e); + } } /** diff --git a/jetty-core/jetty-http/src/test/java/org/eclipse/jetty/http/HttpDateTimeTest.java b/jetty-core/jetty-http/src/test/java/org/eclipse/jetty/http/HttpDateTimeTest.java index f0342799afed..9624b3ffe55f 100644 --- a/jetty-core/jetty-http/src/test/java/org/eclipse/jetty/http/HttpDateTimeTest.java +++ b/jetty-core/jetty-http/src/test/java/org/eclipse/jetty/http/HttpDateTimeTest.java @@ -111,6 +111,7 @@ public static Stream dateTimeInvalid() // - invalid day args.add(Arguments.of("Tue, 00 Apr 2024 17:28:27 GMT", "Invalid [day]")); + args.add(Arguments.of("Tue, 31 Feb 2020 17:28:27 GMT", "Invalid date/time")); // - long form month args.add(Arguments.of("Wed, 22 August 1984 01:02:03 GMT", "Missing [month]")); // - no day