You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by co...@apache.org on 2015/02/04 15:33:51 UTC

svn commit: r1657256 - in /httpd/httpd/trunk: CHANGES modules/lua/lua_request.c

Author: covener
Date: Wed Feb  4 14:33:51 2015
New Revision: 1657256

URL: http://svn.apache.org/r1657256
Log:
Fix bit-shifting of websockets frame fields that would yield wrong opcodes
when the FIN bit was set.  Results in PING not being recognized
by mod_lua.  PR57524

Submitted By: Edward Lu
Committed By: covener


Modified:
    httpd/httpd/trunk/CHANGES
    httpd/httpd/trunk/modules/lua/lua_request.c

Modified: httpd/httpd/trunk/CHANGES
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/CHANGES?rev=1657256&r1=1657255&r2=1657256&view=diff
==============================================================================
--- httpd/httpd/trunk/CHANGES [utf-8] (original)
+++ httpd/httpd/trunk/CHANGES [utf-8] Wed Feb  4 14:33:51 2015
@@ -1,6 +1,10 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache 2.5.0
 
+  *) mod_lua: After a r:wsupgrade(), mod_lua was not properly
+     responding to a websockets PING but instead invoking the specified 
+     script. PR57524. [Edward Lu <Chaosed0 gmail.com>]
+
   *) mod_macro: Clear macros before initialization to avoid use-after-free
      on startup or restart when the module is linked statically. PR 57525
      [apache.org tech.futurequest.net, Yann Ylavic]

Modified: httpd/httpd/trunk/modules/lua/lua_request.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/lua/lua_request.c?rev=1657256&r1=1657255&r2=1657256&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/lua/lua_request.c (original)
+++ httpd/httpd/trunk/modules/lua/lua_request.c Wed Feb  4 14:33:51 2015
@@ -2252,9 +2252,12 @@ static int lua_websocket_read(lua_State
         rv = lua_websocket_readbytes(r->connection, &byte, 1);
     }
     if (rv == APR_SUCCESS) {
-        unsigned char fin, opcode, mask, payload;
-        fin = byte >> 7;
-        opcode = (byte << 4) >> 4;
+        unsigned char ubyte, fin, opcode, mask, payload;
+        ubyte = (unsigned char)byte;
+        /* fin bit is the first bit */
+        fin = ubyte >> (CHAR_BIT - 1);
+        /* opcode is the last four bits (there's 3 reserved bits we don't care about) */
+        opcode = ubyte & 0xf;
         
         /* Get the payload length and mask bit */
         if (plaintext) {
@@ -2264,14 +2267,18 @@ static int lua_websocket_read(lua_State
             rv = lua_websocket_readbytes(r->connection, &byte, 1);
         }
         if (rv == APR_SUCCESS) {
-            mask = byte >> 7;
-            payload = byte - 128;
+            ubyte = (unsigned char)byte;
+            /* Mask is the first bit */
+            mask = ubyte >> (CHAR_BIT - 1);
+            /* Payload is the last 7 bits */
+            payload = ubyte & 0x7f;
             plen = payload;
             
             /* Extended payload? */
             if (payload == 126) {
                 len = 2;
                 if (plaintext) {
+                    /* XXX: apr_socket_recv does not receive len bits, only up to len bits! */
                     rv = apr_socket_recv(sock, (char*) &payload_short, &len);
                 }
                 else {