From 907d3037743cf00e09c41a8936d7924e9d9733ac Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Mon, 16 Jun 2014 10:38:01 +0200 Subject: [PATCH] Added checks on the validity of the streamId. --- .../java/org/eclipse/jetty/http2/parser/DataBodyParser.java | 5 +++++ .../org/eclipse/jetty/http2/parser/HeadersBodyParser.java | 5 +++++ .../org/eclipse/jetty/http2/parser/PriorityBodyParser.java | 5 +++++ .../java/org/eclipse/jetty/http2/parser/ResetBodyParser.java | 5 +++++ .../org/eclipse/jetty/http2/parser/SettingsBodyParser.java | 5 +++++ 5 files changed, 25 insertions(+) diff --git a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/parser/DataBodyParser.java b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/parser/DataBodyParser.java index 3a2e111e0e8..a90e17383c0 100644 --- a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/parser/DataBodyParser.java +++ b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/parser/DataBodyParser.java @@ -62,6 +62,11 @@ public class DataBodyParser extends BodyParser { case PREPARE: { + // SPEC: wrong streamId is treated as connection error. + if (getStreamId() == 0) + { + return notifyConnectionFailure(ErrorCode.PROTOCOL_ERROR, "invalid_data_frame"); + } length = getBodyLength(); if (isPaddingHigh()) { diff --git a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/parser/HeadersBodyParser.java b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/parser/HeadersBodyParser.java index 54b12a2c21c..7c66e91caa0 100644 --- a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/parser/HeadersBodyParser.java +++ b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/parser/HeadersBodyParser.java @@ -73,6 +73,11 @@ public class HeadersBodyParser extends BodyParser { case PREPARE: { + // SPEC: wrong streamId is treated as connection error. + if (getStreamId() == 0) + { + return notifyConnectionFailure(ErrorCode.PROTOCOL_ERROR, "invalid_headers_frame"); + } length = getBodyLength(); if (isPaddingHigh()) { diff --git a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/parser/PriorityBodyParser.java b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/parser/PriorityBodyParser.java index b845266273a..1389e1df168 100644 --- a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/parser/PriorityBodyParser.java +++ b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/parser/PriorityBodyParser.java @@ -51,6 +51,11 @@ public class PriorityBodyParser extends BodyParser { case PREPARE: { + // SPEC: wrong streamId is treated as connection error. + if (getStreamId() == 0) + { + return notifyConnectionFailure(ErrorCode.PROTOCOL_ERROR, "invalid_priority_frame"); + } int length = getBodyLength(); if (length != 5) { diff --git a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/parser/ResetBodyParser.java b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/parser/ResetBodyParser.java index f74456eb384..15c1e8b1bbc 100644 --- a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/parser/ResetBodyParser.java +++ b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/parser/ResetBodyParser.java @@ -49,6 +49,11 @@ public class ResetBodyParser extends BodyParser { case PREPARE: { + // SPEC: wrong streamId is treated as connection error. + if (getStreamId() == 0) + { + return notifyConnectionFailure(ErrorCode.PROTOCOL_ERROR, "invalid_rst_stream_frame"); + } int length = getBodyLength(); if (length != 4) { diff --git a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/parser/SettingsBodyParser.java b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/parser/SettingsBodyParser.java index d1649fc4dbd..0db05d10bc9 100644 --- a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/parser/SettingsBodyParser.java +++ b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/parser/SettingsBodyParser.java @@ -64,6 +64,11 @@ public class SettingsBodyParser extends BodyParser { case PREPARE: { + // SPEC: wrong streamId is treated as connection error. + if (getStreamId() != 0) + { + return notifyConnectionFailure(ErrorCode.PROTOCOL_ERROR, "invalid_settings_frame"); + } length = getBodyLength(); settings = new HashMap<>(); state = State.SETTING_ID;