]> granicus.if.org Git - php/commitdiff
Access memory which was really allocated
authorAndrey Hristov <andrey@php.net>
Tue, 25 May 2010 22:34:47 +0000 (22:34 +0000)
committerAndrey Hristov <andrey@php.net>
Tue, 25 May 2010 22:34:47 +0000 (22:34 +0000)
ext/mysqlnd/mysqlnd_wireprotocol.c

index 08d470c9fabfbc759c902c1d9c9268a70c7c9de7..af8a4a95da2f37da53cc709ee7388f5577f85d88 100644 (file)
@@ -1908,8 +1908,10 @@ MYSQLND_METHOD(mysqlnd_protocol, get_greet_packet)(MYSQLND_PROTOCOL * const prot
 {
        struct st_mysqlnd_packet_greet * packet = mnd_pecalloc(1, packet_methods[PROT_GREET_PACKET].struct_size, persistent);
        DBG_ENTER("mysqlnd_protocol::get_greet_packet");
-       packet->header.m = &packet_methods[PROT_GREET_PACKET];
-       packet->header.persistent = persistent;
+       if (packet) {
+               packet->header.m = &packet_methods[PROT_GREET_PACKET];
+               packet->header.persistent = persistent;
+       }
        DBG_RETURN(packet);
 }
 /* }}} */
@@ -1921,8 +1923,10 @@ MYSQLND_METHOD(mysqlnd_protocol, get_auth_packet)(MYSQLND_PROTOCOL * const proto
 {
        struct st_mysqlnd_packet_auth * packet = mnd_pecalloc(1, packet_methods[PROT_AUTH_PACKET].struct_size, persistent);
        DBG_ENTER("mysqlnd_protocol::get_auth_packet");
-       packet->header.m = &packet_methods[PROT_AUTH_PACKET];
-       packet->header.persistent = persistent;
+       if (packet) {
+               packet->header.m = &packet_methods[PROT_AUTH_PACKET];
+               packet->header.persistent = persistent;
+       }
        DBG_RETURN(packet);
 }
 /* }}} */
@@ -1934,8 +1938,10 @@ MYSQLND_METHOD(mysqlnd_protocol, get_ok_packet)(MYSQLND_PROTOCOL * const protoco
 {
        struct st_mysqlnd_packet_ok * packet = mnd_pecalloc(1, packet_methods[PROT_OK_PACKET].struct_size, persistent);
        DBG_ENTER("mysqlnd_protocol::get_ok_packet");
-       packet->header.m = &packet_methods[PROT_OK_PACKET];
-       packet->header.persistent = persistent;
+       if (packet) {
+               packet->header.m = &packet_methods[PROT_OK_PACKET];
+               packet->header.persistent = persistent;
+       }
        DBG_RETURN(packet);
 }
 /* }}} */
@@ -1947,8 +1953,10 @@ MYSQLND_METHOD(mysqlnd_protocol, get_eof_packet)(MYSQLND_PROTOCOL * const protoc
 {
        struct st_mysqlnd_packet_eof * packet = mnd_pecalloc(1, packet_methods[PROT_EOF_PACKET].struct_size, persistent);
        DBG_ENTER("mysqlnd_protocol::get_eof_packet");
-       packet->header.m = &packet_methods[PROT_EOF_PACKET];
-       packet->header.persistent = persistent;
+       if (packet) {
+               packet->header.m = &packet_methods[PROT_EOF_PACKET];
+               packet->header.persistent = persistent;
+       }
        DBG_RETURN(packet);
 }
 /* }}} */
@@ -1960,8 +1968,10 @@ MYSQLND_METHOD(mysqlnd_protocol, get_command_packet)(MYSQLND_PROTOCOL * const pr
 {
        struct st_mysqlnd_packet_command * packet = mnd_pecalloc(1, packet_methods[PROT_CMD_PACKET].struct_size, persistent);
        DBG_ENTER("mysqlnd_protocol::get_command_packet");
-       packet->header.m = &packet_methods[PROT_CMD_PACKET];
-       packet->header.persistent = persistent;
+       if (packet) {
+               packet->header.m = &packet_methods[PROT_CMD_PACKET];
+               packet->header.persistent = persistent;
+       }
        DBG_RETURN(packet);
 }
 /* }}} */
@@ -1973,8 +1983,10 @@ MYSQLND_METHOD(mysqlnd_protocol, get_rset_header_packet)(MYSQLND_PROTOCOL * cons
 {
        struct st_mysqlnd_packet_rset_header * packet = mnd_pecalloc(1, packet_methods[PROT_RSET_HEADER_PACKET].struct_size, persistent);
        DBG_ENTER("mysqlnd_protocol::get_rset_header_packet");
-       packet->header.m = &packet_methods[PROT_RSET_HEADER_PACKET];
-       packet->header.persistent = persistent;
+       if (packet) {
+               packet->header.m = &packet_methods[PROT_RSET_HEADER_PACKET];
+               packet->header.persistent = persistent;
+       }
        DBG_RETURN(packet);
 }
 /* }}} */
@@ -1986,8 +1998,10 @@ MYSQLND_METHOD(mysqlnd_protocol, get_result_field_packet)(MYSQLND_PROTOCOL * con
 {
        struct st_mysqlnd_packet_res_field * packet = mnd_pecalloc(1, packet_methods[PROT_RSET_FLD_PACKET].struct_size, persistent);
        DBG_ENTER("mysqlnd_protocol::get_result_field_packet");
-       packet->header.m = &packet_methods[PROT_RSET_FLD_PACKET];
-       packet->header.persistent = persistent;
+       if (packet) {
+               packet->header.m = &packet_methods[PROT_RSET_FLD_PACKET];
+               packet->header.persistent = persistent;
+       }
        DBG_RETURN(packet);
 }
 /* }}} */
@@ -1999,8 +2013,10 @@ MYSQLND_METHOD(mysqlnd_protocol, get_row_packet)(MYSQLND_PROTOCOL * const protoc
 {
        struct st_mysqlnd_packet_row * packet = mnd_pecalloc(1, packet_methods[PROT_ROW_PACKET].struct_size, persistent);
        DBG_ENTER("mysqlnd_protocol::get_row_packet");
-       packet->header.m = &packet_methods[PROT_ROW_PACKET];
-       packet->header.persistent = persistent;
+       if (packet) {
+               packet->header.m = &packet_methods[PROT_ROW_PACKET];
+               packet->header.persistent = persistent;
+       }
        DBG_RETURN(packet);
 }
 /* }}} */
@@ -2012,8 +2028,10 @@ MYSQLND_METHOD(mysqlnd_protocol, get_stats_packet)(MYSQLND_PROTOCOL * const prot
 {
        struct st_mysqlnd_packet_stats * packet = mnd_pecalloc(1, packet_methods[PROT_STATS_PACKET].struct_size, persistent);
        DBG_ENTER("mysqlnd_protocol::get_stats_packet");
-       packet->header.m = &packet_methods[PROT_STATS_PACKET];
-       packet->header.persistent = persistent;
+       if (packet) {
+               packet->header.m = &packet_methods[PROT_STATS_PACKET];
+               packet->header.persistent = persistent;
+       }
        DBG_RETURN(packet);
 }
 /* }}} */
@@ -2025,8 +2043,10 @@ MYSQLND_METHOD(mysqlnd_protocol, get_prepare_response_packet)(MYSQLND_PROTOCOL *
 {
        struct st_mysqlnd_packet_prepare_response * packet = mnd_pecalloc(1, packet_methods[PROT_PREPARE_RESP_PACKET].struct_size, persistent);
        DBG_ENTER("mysqlnd_protocol::get_prepare_response_packet");
-       packet->header.m = &packet_methods[PROT_PREPARE_RESP_PACKET];
-       packet->header.persistent = persistent;
+       if (packet) {
+               packet->header.m = &packet_methods[PROT_PREPARE_RESP_PACKET];
+               packet->header.persistent = persistent;
+       }
        DBG_RETURN(packet);
 }
 /* }}} */
@@ -2038,8 +2058,10 @@ MYSQLND_METHOD(mysqlnd_protocol, get_change_user_response_packet)(MYSQLND_PROTOC
 {
        struct st_mysqlnd_packet_chg_user_resp * packet = mnd_pecalloc(1, packet_methods[PROT_CHG_USER_RESP_PACKET].struct_size, persistent);
        DBG_ENTER("mysqlnd_protocol::get_change_user_response_packet");
-       packet->header.m = &packet_methods[PROT_CHG_USER_RESP_PACKET];
-       packet->header.persistent = persistent;
+       if (packet) {
+               packet->header.m = &packet_methods[PROT_CHG_USER_RESP_PACKET];
+               packet->header.persistent = persistent;
+       }
        DBG_RETURN(packet);
 }
 /* }}} */
@@ -2070,9 +2092,10 @@ mysqlnd_protocol_init(zend_bool persistent TSRMLS_DC)
 
        DBG_ENTER("mysqlnd_protocol_init");
        DBG_INF_FMT("persistent=%d", persistent);
-       ret->persistent = persistent;
-
-       ret->m = mysqlnd_mysqlnd_protocol_methods;
+       if (ret) {
+               ret->persistent = persistent;
+               ret->m = mysqlnd_mysqlnd_protocol_methods;
+       }
 
        DBG_RETURN(ret);
 }