From 3819ed03996f1497512bffb445f81398a0bbaa17 Mon Sep 17 00:00:00 2001 From: Eric Gribkoff Date: Thu, 25 May 2017 15:24:49 -0700 Subject: [PATCH] Avoid NPE with Http/2 settings id in the experimental range --- .../java/okhttp3/internal/http2/Http2Test.java | 15 +++++++++++++++ .../java/okhttp3/internal/http2/Settings.java | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/okhttp-tests/src/test/java/okhttp3/internal/http2/Http2Test.java b/okhttp-tests/src/test/java/okhttp3/internal/http2/Http2Test.java index b1df905a4fb1..24ec759c2d92 100644 --- a/okhttp-tests/src/test/java/okhttp3/internal/http2/Http2Test.java +++ b/okhttp-tests/src/test/java/okhttp3/internal/http2/Http2Test.java @@ -278,6 +278,21 @@ public void pushPromise(int streamId, int promisedStreamId, List
headerB assertEquals(settingValue.intValue(), 1); } + @Test public void readSettingsFrameExperimentalId() throws IOException { + writeMedium(frame, 6); // 2 for the code and 4 for the value + frame.writeByte(Http2.TYPE_SETTINGS); + frame.writeByte(Http2.FLAG_NONE); + frame.writeInt(0); // Settings are always on the connection stream 0. + frame.write(ByteString.decodeHex("f000")); // Id reserved for experimental use. + frame.writeInt(1); + + reader.nextFrame(false, new BaseTestHandler() { + @Override public void settings(boolean clearPrevious, Settings settings) { + // no-op + } + }); + } + @Test public void readSettingsFrameNegativeWindowSize() throws IOException { writeMedium(frame, 6); // 2 for the code and 4 for the value frame.writeByte(Http2.TYPE_SETTINGS); diff --git a/okhttp/src/main/java/okhttp3/internal/http2/Settings.java b/okhttp/src/main/java/okhttp3/internal/http2/Settings.java index c677727d94af..5b548de484ae 100644 --- a/okhttp/src/main/java/okhttp3/internal/http2/Settings.java +++ b/okhttp/src/main/java/okhttp3/internal/http2/Settings.java @@ -56,7 +56,7 @@ void clear() { } Settings set(int id, int value) { - if (id >= values.length) { + if (id < 0 || id >= values.length) { return this; // Discard unknown settings. }