]> granicus.if.org Git - php/commitdiff
Fix crash when tracing is enabled. Position after buffer was used also
authorAndrey Hristov <andrey@php.net>
Fri, 12 Jun 2009 13:24:37 +0000 (13:24 +0000)
committerAndrey Hristov <andrey@php.net>
Fri, 12 Jun 2009 13:24:37 +0000 (13:24 +0000)
direct usage of MYSQLND_STRING pointer instead of the "s" property of the
structure.

ext/mysqlnd/mysqlnd_enum_n_def.h
ext/mysqlnd/mysqlnd_statistics.c
ext/mysqlnd/mysqlnd_statistics.h
ext/mysqlnd/mysqlnd_wireprotocol.c

index a1a1ae0eba1d5f325a08e1ed2f295c6df4c7ea05..8b7c4162627574311fdb18ec857b34aaf852af75 100644 (file)
@@ -142,7 +142,6 @@ typedef enum mysqlnd_option
        MYSQLND_OPT_NET_READ_BUFFER_SIZE = 203,
 } enum_mysqlnd_option;
 
-
 typedef enum mysqlnd_field_types
 {
        MYSQL_TYPE_DECIMAL,
@@ -177,7 +176,6 @@ typedef enum mysqlnd_field_types
 /* Please update this if there is a new type after MYSQL_TYPE_GEOMETRY */
 #define MYSQL_TYPE_LAST                MYSQL_TYPE_GEOMETRY
 
-
 typedef enum mysqlnd_server_option
 {
        MYSQL_OPTION_MULTI_STATEMENTS_ON,
@@ -241,7 +239,6 @@ typedef enum mysqlnd_server_option
 /* see mysqlnd_charset.c for more information */
 #define MYSQLND_BINARY_CHARSET_NR      63
 
-
 /*
           /-----> CONN_CLOSE  <---------------\
          |           ^                         \
@@ -261,7 +258,6 @@ typedef enum mysqlnd_connection_state
        CONN_QUIT_SENT, /* object is "destroyed" at this stage */
 } enum_mysqlnd_connection_state;
 
-
 typedef enum mysqlnd_stmt_state
 {
        MYSQLND_STMT_INITTED = 0,
@@ -272,13 +268,11 @@ typedef enum mysqlnd_stmt_state
        MYSQLND_STMT_USER_FETCHING, /* fetch_row_buff or fetch_row_unbuf */
 } enum_mysqlnd_stmt_state;
 
-
 typedef enum param_bind_flags
 {
        MYSQLND_PARAM_BIND_BLOB_USED = 1
 } enum_param_bind_flags;
 
-
 /* PS */
 enum mysqlnd_stmt_attr
 {
@@ -286,7 +280,6 @@ enum mysqlnd_stmt_attr
        STMT_ATTR_CURSOR_TYPE,
        STMT_ATTR_PREFETCH_ROWS
 };
-
 enum myslqnd_cursor_type
 {
        CURSOR_TYPE_NO_CURSOR= 0,
@@ -294,7 +287,6 @@ enum myslqnd_cursor_type
        CURSOR_TYPE_FOR_UPDATE= 2,
        CURSOR_TYPE_SCROLLABLE= 4
 };
-
 typedef enum mysqlnd_connection_close_type
 {
        MYSQLND_CLOSE_EXPLICIT = 0,
@@ -303,7 +295,6 @@ typedef enum mysqlnd_connection_close_type
        MYSQLND_CLOSE_LAST      /* for checking, should always be last */
 } enum_connection_close_type;
 
-
 typedef enum mysqlnd_collected_stats
 {
        STAT_BYTES_SENT,
index 4e6089b915934c15213f0f351dd0d1e8f49b4f09..7e6ea5506012750c5a5a2fe9816ed9bcd5f0abff 100644 (file)
@@ -168,7 +168,7 @@ mysqlnd_fill_stats_hash(const MYSQLND_STATS * const stats, zval *return_value TS
                UChar *ustr, *tstr;
                int ulen, tlen;
 #endif
-               char tmp[22];
+               char tmp[25];
                
                sprintf((char *)&tmp, MYSQLND_LLU_SPEC, stats->values[i]);
 #if PHP_MAJOR_VERSION >= 6
index dc36aa777c6dbad3a616a6f3c7fadb1a845d1e63..eb9bdb31906a595559dc629fb3e5c861ffcbfdc9 100644 (file)
@@ -39,7 +39,8 @@ extern const MYSQLND_STRING mysqlnd_stats_values_names[];
 #define MYSQLND_INC_GLOBAL_STATISTIC(statistic) \
  { \
        if (MYSQLND_G(collect_statistics) && (statistic) != STAT_LAST) { \
-               DBG_INF_FMT("Global stat increase [%s]", mysqlnd_stats_values_names[(statistic)]); \
+               DBG_INF_FMT("Global stat increase [%s]", mysqlnd_stats_values_names[(statistic)].s); \
+                       \
                tsrm_mutex_lock(mysqlnd_global_stats->LOCK_access); \
                mysqlnd_global_stats->values[(statistic)]++; \
                tsrm_mutex_unlock(mysqlnd_global_stats->LOCK_access); \
@@ -49,7 +50,8 @@ extern const MYSQLND_STRING mysqlnd_stats_values_names[];
 #define MYSQLND_DEC_CONN_STATISTIC(conn_stats, statistic) \
  { \
        if (MYSQLND_G(collect_statistics) && (statistic) != STAT_LAST) { \
-               DBG_INF_FMT("Global&conn stat decrease [%s]", mysqlnd_stats_values_names[(statistic)]); \
+               DBG_INF_FMT("Global&conn stat decrease [%s]", mysqlnd_stats_values_names[(statistic)].s); \
+                       \
                tsrm_mutex_lock(mysqlnd_global_stats->LOCK_access); \
                mysqlnd_global_stats->values[(statistic)]--; \
                tsrm_mutex_unlock(mysqlnd_global_stats->LOCK_access); \
@@ -64,11 +66,15 @@ extern const MYSQLND_STRING mysqlnd_stats_values_names[];
        if (MYSQLND_G(collect_statistics)) { \
                uint64_t v1 = (uint64_t) (value1); \
                uint64_t v2 = (uint64_t) (value2); \
-               DBG_INF_FMT("Global stat increase [%s] [%s]", mysqlnd_stats_values_names[(statistic1)], mysqlnd_stats_values_names[(statistic2)]); \
+               enum_mysqlnd_collected_stats _s1 = (statistic1);\
+               enum_mysqlnd_collected_stats _s2 = (statistic2);\
+                                                                \
+               if (_s1 != STAT_LAST) DBG_INF_FMT("Global stat increase1 [%s]", mysqlnd_stats_values_names[_s1].s); \
+               if (_s2 != STAT_LAST) DBG_INF_FMT("Global stat increase2 [%s]", mysqlnd_stats_values_names[_s2].s); \
                                                                                \
                tsrm_mutex_lock(mysqlnd_global_stats->LOCK_access); \
-               if (statistic1 != STAT_LAST) mysqlnd_global_stats->values[(statistic1)]+= v1; \
-               if (statistic2 != STAT_LAST) mysqlnd_global_stats->values[(statistic2)]+= v2; \
+               if (_s1 != STAT_LAST) mysqlnd_global_stats->values[_s1]+= v1; \
+               if (_s2 != STAT_LAST) mysqlnd_global_stats->values[_s2]+= v2; \
                tsrm_mutex_unlock(mysqlnd_global_stats->LOCK_access); \
        }\
  }
@@ -76,7 +82,8 @@ extern const MYSQLND_STRING mysqlnd_stats_values_names[];
 #define MYSQLND_INC_CONN_STATISTIC(conn_stats, statistic) \
  { \
        if (MYSQLND_G(collect_statistics) && (statistic) != STAT_LAST) { \
-               DBG_INF_FMT("Global&Conn stat increase [%s]", mysqlnd_stats_values_names[(statistic)]); \
+               DBG_INF_FMT("Global&Conn stat increase [%s]", mysqlnd_stats_values_names[(statistic)].s); \
+                       \
                tsrm_mutex_lock(mysqlnd_global_stats->LOCK_access); \
                mysqlnd_global_stats->values[(statistic)]++; \
                tsrm_mutex_unlock(mysqlnd_global_stats->LOCK_access); \
@@ -90,7 +97,8 @@ extern const MYSQLND_STRING mysqlnd_stats_values_names[];
  { \
        if (MYSQLND_G(collect_statistics) && (statistic) != STAT_LAST) { \
                uint64_t v = (uint64_t) (value); \
-               DBG_INF_FMT("Global&Conn stat increase w value [%s]", mysqlnd_stats_values_names[(statistic)]); \
+               DBG_INF_FMT("Global&Conn stat increase w value [%s]", mysqlnd_stats_values_names[(statistic)].s); \
+                       \
                tsrm_mutex_lock(mysqlnd_global_stats->LOCK_access); \
                mysqlnd_global_stats->values[(statistic)] += v; \
                tsrm_mutex_unlock(mysqlnd_global_stats->LOCK_access); \
@@ -105,14 +113,19 @@ extern const MYSQLND_STRING mysqlnd_stats_values_names[];
        if (MYSQLND_G(collect_statistics)) { \
                uint64_t v1 = (uint64_t) (value1); \
                uint64_t v2 = (uint64_t) (value2); \
+               enum_mysqlnd_collected_stats _s1 = (statistic1);\
+               enum_mysqlnd_collected_stats _s2 = (statistic2);\
                                                                 \
+               if (_s1 != STAT_LAST) DBG_INF_FMT("Global stat increase1 [%s]", mysqlnd_stats_values_names[_s1].s); \
+               if (_s2 != STAT_LAST) DBG_INF_FMT("Global stat increase2 [%s]", mysqlnd_stats_values_names[_s2].s); \
+                                       \
                tsrm_mutex_lock(mysqlnd_global_stats->LOCK_access); \
-               if (statistic1 != STAT_LAST) mysqlnd_global_stats->values[(statistic1)]+= v1; \
-               if (statistic2 != STAT_LAST) mysqlnd_global_stats->values[(statistic2)]+= v2; \
+               if (_s1 != STAT_LAST) mysqlnd_global_stats->values[_s1]+= v1; \
+               if (_s2 != STAT_LAST) mysqlnd_global_stats->values[_s2]+= v2; \
                tsrm_mutex_unlock(mysqlnd_global_stats->LOCK_access); \
                if ((conn_stats)) { \
-                       if (statistic1 != STAT_LAST) ((MYSQLND_STATS *) conn_stats)->values[(statistic1)]+= v1; \
-                       if (statistic2 != STAT_LAST) ((MYSQLND_STATS *) conn_stats)->values[(statistic2)]+= v2; \
+                       if (_s1 != STAT_LAST) ((MYSQLND_STATS *) conn_stats)->values[_s1]+= v1; \
+                       if (_s2 != STAT_LAST) ((MYSQLND_STATS *) conn_stats)->values[_s2]+= v2; \
                } \
        } \
  }
@@ -124,16 +137,23 @@ extern const MYSQLND_STRING mysqlnd_stats_values_names[];
                uint64_t v1 = (uint64_t) (value1); \
                uint64_t v2 = (uint64_t) (value2); \
                uint64_t v3 = (uint64_t) (value3); \
+               enum_mysqlnd_collected_stats _s1 = (statistic1); \
+               enum_mysqlnd_collected_stats _s2 = (statistic2); \
+               enum_mysqlnd_collected_stats _s3 = (statistic3); \
+                                                                \
+               if (_s1 != STAT_LAST) DBG_INF_FMT("Global stat increase1 [%s]", mysqlnd_stats_values_names[_s1].s); \
+               if (_s2 != STAT_LAST) DBG_INF_FMT("Global stat increase2 [%s]", mysqlnd_stats_values_names[_s2].s); \
+               if (_s3 != STAT_LAST) DBG_INF_FMT("Global stat increase3 [%s]", mysqlnd_stats_values_names[_s3].s); \
                                                                                \
                tsrm_mutex_lock(mysqlnd_global_stats->LOCK_access); \
-               if (statistic1 != STAT_LAST) mysqlnd_global_stats->values[(statistic1)]+= v1; \
-               if (statistic2 != STAT_LAST) mysqlnd_global_stats->values[(statistic2)]+= v2; \
-               if (statistic3 != STAT_LAST) mysqlnd_global_stats->values[(statistic3)]+= v3; \
+               if (_s1 != STAT_LAST) mysqlnd_global_stats->values[_s1]+= v1; \
+               if (_s2 != STAT_LAST) mysqlnd_global_stats->values[_s2]+= v2; \
+               if (_s3 != STAT_LAST) mysqlnd_global_stats->values[_s3]+= v3; \
                tsrm_mutex_unlock(mysqlnd_global_stats->LOCK_access); \
                if ((conn_stats)) { \
-                       if (statistic1 != STAT_LAST) ((MYSQLND_STATS *) conn_stats)->values[(statistic1)]+= v1; \
-                       if (statistic2 != STAT_LAST) ((MYSQLND_STATS *) conn_stats)->values[(statistic2)]+= v2; \
-                       if (statistic3 != STAT_LAST) ((MYSQLND_STATS *) conn_stats)->values[(statistic3)]+= v3; \
+                       if (_s1 != STAT_LAST) ((MYSQLND_STATS *) conn_stats)->values[_s1]+= v1; \
+                       if (_s2 != STAT_LAST) ((MYSQLND_STATS *) conn_stats)->values[_s2]+= v2; \
+                       if (_s3 != STAT_LAST) ((MYSQLND_STATS *) conn_stats)->values[_s3]+= v3; \
                } \
        } \
  }
@@ -144,7 +164,7 @@ extern const MYSQLND_STRING mysqlnd_stats_values_names[];
 #define MYSQLND_INC_GLOBAL_STATISTIC(statistic) \
  { \
        if (MYSQLND_G(collect_statistics) && (statistic) != STAT_LAST) { \
-               DBG_INF_FMT("Global stat increase [%s]", mysqlnd_stats_values_names[(statistic)]); \
+               DBG_INF_FMT("Global stat increase [%s]", mysqlnd_stats_values_names[(statistic)].s); \
                mysqlnd_global_stats->values[(statistic)]++; \
        } \
  }
@@ -153,7 +173,7 @@ extern const MYSQLND_STRING mysqlnd_stats_values_names[];
 #define MYSQLND_DEC_CONN_STATISTIC(conn_stats, statistic) \
  { \
        if (MYSQLND_G(collect_statistics) && (statistic) != STAT_LAST) { \
-               DBG_INF_FMT("Global&Conn stat decrease [%s]", mysqlnd_stats_values_names[(statistic)]); \
+               DBG_INF_FMT("Global&Conn stat decrease [%s]", mysqlnd_stats_values_names[(statistic)].s); \
                mysqlnd_global_stats->values[(statistic)]--; \
                if ((conn_stats)) { \
                        ((MYSQLND_STATS *) conn_stats)->values[(statistic)]--; \
@@ -166,17 +186,21 @@ extern const MYSQLND_STRING mysqlnd_stats_values_names[];
        if (MYSQLND_G(collect_statistics)) { \
                uint64_t v1 = (uint64_t) (value1); \
                uint64_t v2 = (uint64_t) (value2); \
-               DBG_INF_FMT("Global stat increase [%s] [%s]", mysqlnd_stats_values_names[(statistic1)], mysqlnd_stats_values_names[(statistic2)]); \
+               enum_mysqlnd_collected_stats _s1 = (statistic1);\
+               enum_mysqlnd_collected_stats _s2 = (statistic2);\
+                                                                \
+               if (_s1 != STAT_LAST) DBG_INF_FMT("Global stat increase1 [%s]", mysqlnd_stats_values_names[_s1].s); \
+               if (_s2 != STAT_LAST) DBG_INF_FMT("Global stat increase2 [%s]", mysqlnd_stats_values_names[_s2].s); \
                        \
-               if (statistic1 != STAT_LAST) mysqlnd_global_stats->values[(statistic1)]+= v1; \
-               if (statistic2 != STAT_LAST) mysqlnd_global_stats->values[(statistic2)]+= v2; \
+               if (_s1 != STAT_LAST) mysqlnd_global_stats->values[_s1]+= v1; \
+               if (_s2 != STAT_LAST) mysqlnd_global_stats->values[_s2]+= v2; \
        }\
  }
 
 #define MYSQLND_INC_CONN_STATISTIC(conn_stats, statistic) \
  { \
        if (MYSQLND_G(collect_statistics) && (statistic) != STAT_LAST) { \
-               DBG_INF_FMT("Global&Conn stat increase [%s]", mysqlnd_stats_values_names[(statistic)]); \
+               DBG_INF_FMT("Global&Conn stat increase [%s]", mysqlnd_stats_values_names[(statistic)].s); \
                mysqlnd_global_stats->values[(statistic)]++; \
                if ((conn_stats)) { \
                        ((MYSQLND_STATS *) conn_stats)->values[(statistic)]++; \
@@ -188,7 +212,7 @@ extern const MYSQLND_STRING mysqlnd_stats_values_names[];
  { \
        if (MYSQLND_G(collect_statistics) && (statistic) != STAT_LAST) { \
                uint64_t v = (uint64_t) (value); \
-               DBG_INF_FMT("Global&Conn stats increase w value [%s]", mysqlnd_stats_values_names[(statistic)]); \
+               DBG_INF_FMT("Global&Conn stats increase w value [%s]", mysqlnd_stats_values_names[(statistic)].s); \
                mysqlnd_global_stats->values[(statistic)] += v; \
                if ((conn_stats)) { \
                        ((MYSQLND_STATS *) conn_stats)->values[(statistic)] += v; \
@@ -201,12 +225,16 @@ extern const MYSQLND_STRING mysqlnd_stats_values_names[];
        if (MYSQLND_G(collect_statistics)) { \
                uint64_t v1 = (uint64_t) (value1); \
                uint64_t v2 = (uint64_t) (value2); \
+               enum_mysqlnd_collected_stats _s1 = (statistic1);\
+               enum_mysqlnd_collected_stats _s2 = (statistic2);\
+               if (_s1 != STAT_LAST) DBG_INF_FMT("Global stat increase1 [%s]", mysqlnd_stats_values_names[_s1].s); \
+               if (_s2 != STAT_LAST) DBG_INF_FMT("Global stat increase2 [%s]", mysqlnd_stats_values_names[_s2].s); \
                                                                 \
-               if (statistic1 != STAT_LAST) mysqlnd_global_stats->values[(statistic1)]+= v1; \
-               if (statistic2 != STAT_LAST) mysqlnd_global_stats->values[(statistic2)]+= v2; \
+               if (_s1 != STAT_LAST) mysqlnd_global_stats->values[_s1]+= v1; \
+               if (_s2 != STAT_LAST) mysqlnd_global_stats->values[_s2]+= v2; \
                if ((conn_stats)) { \
-                       if (statistic1 != STAT_LAST) ((MYSQLND_STATS *) conn_stats)->values[(statistic1)]+= v1; \
-                       if (statistic2 != STAT_LAST) ((MYSQLND_STATS *) conn_stats)->values[(statistic2)]+= v2; \
+                       if (_s1 != STAT_LAST) ((MYSQLND_STATS *) conn_stats)->values[_s1]+= v1; \
+                       if (_s2 != STAT_LAST) ((MYSQLND_STATS *) conn_stats)->values[_s2]+= v2; \
                } \
        } \
  }
@@ -217,14 +245,21 @@ extern const MYSQLND_STRING mysqlnd_stats_values_names[];
                uint64_t v1 = (uint64_t) (value1); \
                uint64_t v2 = (uint64_t) (value2); \
                uint64_t v3 = (uint64_t) (value3); \
+               enum_mysqlnd_collected_stats _s1 = (statistic1); \
+               enum_mysqlnd_collected_stats _s2 = (statistic2); \
+               enum_mysqlnd_collected_stats _s3 = (statistic3); \
+                                                                \
+               if (_s1 != STAT_LAST) DBG_INF_FMT("Global stat increase1 [%s]", mysqlnd_stats_values_names[_s1].s); \
+               if (_s2 != STAT_LAST) DBG_INF_FMT("Global stat increase2 [%s]", mysqlnd_stats_values_names[_s2].s); \
+               if (_s3 != STAT_LAST) DBG_INF_FMT("Global stat increase3 [%s]", mysqlnd_stats_values_names[_s3].s); \
                                                                \
-               if (statistic1 != STAT_LAST) mysqlnd_global_stats->values[(statistic1)]+= v1; \
-               if (statistic2 != STAT_LAST) mysqlnd_global_stats->values[(statistic2)]+= v2; \
-               if (statistic3 != STAT_LAST) mysqlnd_global_stats->values[(statistic3)]+= v3; \
+               if (_s1 != STAT_LAST) mysqlnd_global_stats->values[_s1]+= v1; \
+               if (_s2 != STAT_LAST) mysqlnd_global_stats->values[_s2]+= v2; \
+               if (_s3 != STAT_LAST) mysqlnd_global_stats->values[_s3]+= v3; \
                if ((conn_stats)) { \
-                       if (statistic1 != STAT_LAST) ((MYSQLND_STATS *) conn_stats)->values[(statistic1)]+= v1; \
-                       if (statistic2 != STAT_LAST) ((MYSQLND_STATS *) conn_stats)->values[(statistic2)]+= v2; \
-                       if (statistic3 != STAT_LAST) ((MYSQLND_STATS *) conn_stats)->values[(statistic3)]+= v3; \
+                       if (_s1 != STAT_LAST) ((MYSQLND_STATS *) conn_stats)->values[_s1]+= v1; \
+                       if (_s2 != STAT_LAST) ((MYSQLND_STATS *) conn_stats)->values[_s2]+= v2; \
+                       if (_s3 != STAT_LAST) ((MYSQLND_STATS *) conn_stats)->values[_s3]+= v3; \
                } \
        } \
  }
index 94e20752d22cd1c7411b1e906254c0a5627da3f5..9ff74f078c4861a051a0fa1adafa7939a9dc817f 100644 (file)
@@ -42,7 +42,6 @@
 #define MYSQLND_DUMP_HEADER_N_BODY2
 #define MYSQLND_DUMP_HEADER_N_BODY_FULL2
 
-
 #define        PACKET_READ_HEADER_AND_BODY(packet, conn, buf, buf_size, packet_type_as_text, packet_type) \
        { \
                if (FAIL == mysqlnd_read_header((conn), &((packet)->header) TSRMLS_CC)) {\
@@ -70,7 +69,6 @@
                                                                                        1); \
        }
 
-
 extern mysqlnd_packet_methods packet_methods[];
 
 static const char *unknown_sqlstate= "HY000";
@@ -811,7 +809,7 @@ php_mysqlnd_ok_read(void *_packet, MYSQLND *conn TSRMLS_DC)
        p+= 2;
 
        /* There is a message */
-       if (packet->header.size > (size_t)(p - buf) && (i = php_mysqlnd_net_field_length(&p))) {
+       if (packet->header.size > (size_t) (p - buf) && (i = php_mysqlnd_net_field_length(&p))) {
                packet->message = pestrndup((char *)p, MIN(i, sizeof(buf) - (p - buf)), conn->persistent);
                packet->message_len = i;
        } else {
@@ -1045,7 +1043,7 @@ php_mysqlnd_rset_header_read(void *_packet, MYSQLND *conn TSRMLS_DC)
                        packet->warning_count = uint2korr(p);
                        p+=2;
                        /* Check for additional textual data */
-                       if (packet->header.size  > (size_t)(p - buf) && (len = php_mysqlnd_net_field_length(&p))) {
+                       if (packet->header.size  > (size_t) (p - buf) && (len = php_mysqlnd_net_field_length(&p))) {
                                packet->info_or_local_file = mnd_pemalloc(len + 1, conn->persistent);
                                memcpy(packet->info_or_local_file, p, len);
                                packet->info_or_local_file[len] = '\0';
@@ -1946,7 +1944,7 @@ php_mysqlnd_prepare_read(void *_packet, MYSQLND *conn TSRMLS_DC)
        DBG_INF_FMT("Prepare packet read: stmt_id=%d fields=%d params=%d",
                                packet->stmt_id, packet->field_count, packet->param_count);
 
-       if ((size_t)(p - begin) > packet->header.size) {
+       if ((size_t) (p - begin) > packet->header.size) {
                DBG_ERR_FMT("PREPARE packet %d bytes shorter than expected", p - begin - packet->header.size);
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "PREPARE packet "MYSQLND_SZ_T_SPEC" bytes shorter than expected",
                                                 p - begin - packet->header.size);