autobahn reject noncontinuation based on pending FIN state
authorAndy Green <andy.green@linaro.org>
Mon, 28 Dec 2015 09:05:40 +0000 (17:05 +0800)
committerAndy Green <andy.green@linaro.org>
Mon, 28 Dec 2015 14:29:57 +0000 (22:29 +0800)
Signed-off-by: Andy Green <andy.green@linaro.org>
lib/client-parser.c
lib/private-libwebsockets.h

index 4157e08..0811cc9 100644 (file)
@@ -72,13 +72,25 @@ int lws_client_rx_sm(struct lws *wsi, unsigned char c)
                                return -1;
                        }
                        wsi->u.ws.final = !!((c >> 7) & 1);
-                       if (wsi->u.ws.final)
+
+                       if (wsi->u.ws.owed_a_fin &&
+                           (wsi->u.ws.opcode == LWSWSOPC_TEXT_FRAME ||
+                            wsi->u.ws.opcode == LWSWSOPC_BINARY_FRAME)) {
+                               lwsl_info("hey you owed us a FIN\n");
+                               return -1;
+                       }
+                       if ((!(wsi->u.ws.opcode & 8)) && wsi->u.ws.final) {
                                wsi->u.ws.continuation_possible = 0;
+                               wsi->u.ws.owed_a_fin = 0;
+                       }
 
                        if ((wsi->u.ws.opcode & 8) && !wsi->u.ws.final) {
                                lwsl_info("control message cannot be fragmented\n");
                                return -1;
                        }
+                       if (!wsi->u.ws.final) {
+                               wsi->u.ws.owed_a_fin = 1;
+                       }
                        switch (wsi->u.ws.opcode) {
                        case LWSWSOPC_TEXT_FRAME:
                        case LWSWSOPC_BINARY_FRAME:
index 15b6f84..06dd64c 100644 (file)
@@ -857,6 +857,7 @@ struct _lws_websocket_related {
        unsigned int payload_is_close:1; /* process as PONG, but it is close */
        unsigned int ping_pending_flag:1;
        unsigned int continuation_possible:1;
+       unsigned int owed_a_fin:1;
 };
 
 struct lws {