Skip to content

Commit b429a84

Browse files
committed
MFH:
Fix a crash introduced yesterday in mysqlnd, non-zts mode - missing if () for STAT_LAST was accessing wrong memory thus overwritting method pointers. Windows doesn't have atoll(), which is C99, C89 has only atoi() + atol(). Win has _atoi64, so use it.
1 parent bbbb0f1 commit b429a84

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

ext/mysqlnd/mysqlnd_statistics.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ extern const MYSQLND_STRING mysqlnd_stats_values_names[];
111111
if (statistic2 != STAT_LAST) mysqlnd_global_stats->values[(statistic2)]+= v2; \
112112
tsrm_mutex_unlock(mysqlnd_global_stats->LOCK_access); \
113113
if ((conn_stats)) { \
114-
((MYSQLND_STATS *) conn_stats)->values[(statistic1)]+= v1; \
115-
((MYSQLND_STATS *) conn_stats)->values[(statistic2)]+= v2; \
114+
if (statistic1 != STAT_LAST) ((MYSQLND_STATS *) conn_stats)->values[(statistic1)]+= v1; \
115+
if (statistic2 != STAT_LAST) ((MYSQLND_STATS *) conn_stats)->values[(statistic2)]+= v2; \
116116
} \
117117
} \
118118
}
@@ -205,8 +205,8 @@ extern const MYSQLND_STRING mysqlnd_stats_values_names[];
205205
if (statistic1 != STAT_LAST) mysqlnd_global_stats->values[(statistic1)]+= v1; \
206206
if (statistic2 != STAT_LAST) mysqlnd_global_stats->values[(statistic2)]+= v2; \
207207
if ((conn_stats)) { \
208-
((MYSQLND_STATS *) conn_stats)->values[(statistic1)]+= v1; \
209-
((MYSQLND_STATS *) conn_stats)->values[(statistic2)]+= v2; \
208+
if (statistic1 != STAT_LAST) ((MYSQLND_STATS *) conn_stats)->values[(statistic1)]+= v1; \
209+
if (statistic2 != STAT_LAST) ((MYSQLND_STATS *) conn_stats)->values[(statistic2)]+= v2; \
210210
} \
211211
} \
212212
}

ext/mysqlnd/mysqlnd_wireprotocol.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,10 +1560,20 @@ void php_mysqlnd_rowp_read_text_protocol(MYSQLND_MEMORY_POOL_CHUNK * row_buffer,
15601560
if (perm_bind.pack_len < SIZEOF_LONG)
15611561
{
15621562
/* direct conversion */
1563-
int64 v = atoll((char *) p);
1563+
int64 v =
1564+
#ifndef PHP_WIN32
1565+
atoll((char *) p);
1566+
#else
1567+
_atoi64((char *) p);
1568+
#endif
15641569
ZVAL_LONG(*current_field, v);
15651570
} else {
1566-
uint64 v = (uint64) atoll((char *) p);
1571+
uint64 v =
1572+
#ifndef PHP_WIN32
1573+
(uint64) atoll((char *) p);
1574+
#else
1575+
(uint64) _atoi64((char *) p);
1576+
#endif
15671577
zend_bool uns = fields_metadata[i].flags & UNSIGNED_FLAG? TRUE:FALSE;
15681578
/* We have to make it ASCIIZ temporarily */
15691579
#if SIZEOF_LONG==8
@@ -1580,13 +1590,11 @@ void php_mysqlnd_rowp_read_text_protocol(MYSQLND_MEMORY_POOL_CHUNK * row_buffer,
15801590
}
15811591
}
15821592
*(p + len) = save;
1583-
} else if (as_int_or_float && perm_bind.php_type == IS_DOUBLE)
1584-
{
1593+
} else if (as_int_or_float && perm_bind.php_type == IS_DOUBLE) {
15851594
zend_uchar save = *(p + len);
15861595
/* We have to make it ASCIIZ temporarily */
15871596
*(p + len) = '\0';
1588-
double v = atof((char *) p);
1589-
ZVAL_DOUBLE(*current_field, v);
1597+
ZVAL_DOUBLE(*current_field, atof((char *) p));
15901598
*(p + len) = save;
15911599
} else
15921600
#endif /* MYSQLND_STRING_TO_INT_CONVERSION */

0 commit comments

Comments
 (0)