]> granicus.if.org Git - php/commitdiff
Fix strict aliasing violation in phpdbg
authorNikita Popov <nikita.ppv@gmail.com>
Fri, 12 Apr 2019 14:46:23 +0000 (16:46 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Fri, 12 Apr 2019 14:46:23 +0000 (16:46 +0200)
By explicitly computing the message length from bytes. This also
makes sure that the length is interpreted in an endianness-independent
manner.

ext/xsl/xsltprocessor.c
sapi/phpdbg/phpdbg_wait.c

index d71460efcfbb0421e1c43b028963d67ebb89f0a3..18443f9efa8fbfb4bc572b254808ea0198b44f8d 100644 (file)
@@ -174,7 +174,7 @@ static char **php_xsl_xslt_make_params(HashTable *parht, int xpath_params)
 static void xsl_ext_function_php(xmlXPathParserContextPtr ctxt, int nargs, int type) /* {{{ */
 {
        xsltTransformContextPtr tctxt;
-       zval *args;
+       zval *args = NULL;
        zval retval;
        int result, i;
        int error = 0;
index 738b4669f2d2e5f953354b571a9d3cbc3d6b78c4..69be24a953ec36f92190154f95b9f038116862cc 100644 (file)
@@ -379,21 +379,25 @@ PHPDBG_COMMAND(wait) /* {{{ */
                return FAILURE;
        }
 
-       char msglen[5];
-       int recvd = 4;
+       unsigned char msglen_buf[4];
+       int needed = 4;
 
        do {
-               recvd -= recv(sr, &(msglen[4 - recvd]), recvd, 0);
-       } while (recvd > 0);
+               needed -= recv(sr, &msglen_buf[4 - needed], needed, 0);
+       } while (needed > 0);
 
-       recvd = *(size_t *) msglen;
-       char *data = emalloc(recvd);
+       uint32_t msglen = (msglen_buf[3] << 24)
+                                       | (msglen_buf[2] << 16)
+                                       | (msglen_buf[1] <<  8)
+                                       | (msglen_buf[0] <<  0);
+       char *data = emalloc(msglen);
+       needed = msglen;
 
        do {
-               recvd -= recv(sr, &(data[(*(int *) msglen) - recvd]), recvd, 0);
-       } while (recvd > 0);
+               needed -= recv(sr, &(data[msglen - needed]), needed, 0);
+       } while (needed > 0);
 
-       phpdbg_webdata_decompress(data, *(int *) msglen);
+       phpdbg_webdata_decompress(data, msglen);
 
        if (PHPDBG_G(socket_fd) != -1) {
                close(PHPDBG_G(socket_fd));