# HG changeset patch
# User Xu Yang <yangxu0823@foxmail.com>
# Date 1598431540 -28800
#      Wed Aug 26 16:45:40 2020 +0800
# Node ID 0c022958d1f0d656feb98f3c88f33e7e2ea6518f
# Parent  7015f26aef904e2ec17b4b6f6387fd3b8298f79d
HTTP/2: check stream identifier other than 0 for GOAWAY frame.

RFC 7540 Section 6.8: An endpoint MUST treat a GOAWAY frame with a stream
identifier other than 0x0 as a connection error of type PROTOCOL_ERROR.

Reject GOAWAY frame with stream identifier other than 0 by closing
connection with PROTOCOL_ERROR.

diff -r 7015f26aef90 -r 0c022958d1f0 src/http/v2/ngx_http_v2.c
--- a/src/http/v2/ngx_http_v2.c	Wed Jul 29 13:28:04 2020 +0300
+++ b/src/http/v2/ngx_http_v2.c	Wed Aug 26 16:45:40 2020 +0800
@@ -2310,6 +2310,20 @@
         return ngx_http_v2_state_save(h2c, pos, end, ngx_http_v2_state_goaway);
     }
 
+    /*
+     * RFC7540  Section 6.8 
+     * The GOAWAY frame applies to the connection, not a specific stream. 
+     * An endpoint MUST treat a GOAWAY frame with a stream identifier other 
+     * than 0x0 as a connection error (Section 5.4.1) of type PROTOCOL_ERROR.
+     */
+    if (h2c->state.sid != 0) {
+        ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
+                      "client sent GOAWAY frame "
+                      "with stream identifier 0");
+
+        return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR);
+    }
+
 #if (NGX_DEBUG)
     h2c->state.length -= NGX_HTTP_V2_GOAWAY_SIZE;
 
