]> granicus.if.org Git - apache/commitdiff
Merge r1657256 from trunk:
authorEric Covener <covener@apache.org>
Wed, 4 Mar 2015 19:17:32 +0000 (19:17 +0000)
committerEric Covener <covener@apache.org>
Wed, 4 Mar 2015 19:17:32 +0000 (19:17 +0000)
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

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1664117 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
modules/lua/lua_request.c

diff --git a/CHANGES b/CHANGES
index 95541dab9f17b787b87c94f3121e2a8f0fb18c55..7212e311b900900f3c819cc5525db72bb63a3d96 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -2,6 +2,10 @@
 
 Changes with Apache 2.4.13
 
+  *) 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>]
+
   *) ab: Add missing longest request (100%) to CSV export.
      [Marcin Fabrykowski <bugzilla fabrykowski.pl>] 
 
index 6dc6b9f53968199b24e6930d4c15da24eddcc204..1ee8421e7173962f02c219466ee580615479cdcf 100644 (file)
@@ -2254,9 +2254,12 @@ static int lua_websocket_read(lua_State *L)
         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) {
@@ -2266,14 +2269,18 @@ static int lua_websocket_read(lua_State *L)
             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 {