Skip to content

Commit 1f7c46b

Browse files
committed
be cautious about the result of strrchr
1 parent 05deaf1 commit 1f7c46b

File tree

1 file changed

+84
-14
lines changed

1 file changed

+84
-14
lines changed

ext/mysqlnd/mysqlnd_alloc.c

+84-14
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,12 @@ void * _mysqlnd_emalloc(size_t size MYSQLND_MEM_D)
8383
#endif
8484
DBG_ENTER(mysqlnd_emalloc_name);
8585

86-
DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno);
86+
#if PHP_DEBUG
87+
{
88+
char * fn = strrchr(__zend_filename, PHP_DIR_SEPARATOR);
89+
DBG_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_filename, __zend_lineno);
90+
}
91+
#endif
8792

8893
#if PHP_DEBUG
8994
/* -1 is also "true" */
@@ -117,7 +122,12 @@ void * _mysqlnd_pemalloc(size_t size, zend_bool persistent MYSQLND_MEM_D)
117122
long * threshold = persistent? &MYSQLND_G(debug_malloc_fail_threshold):&MYSQLND_G(debug_emalloc_fail_threshold);
118123
#endif
119124
DBG_ENTER(mysqlnd_pemalloc_name);
120-
DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno);
125+
#if PHP_DEBUG
126+
{
127+
char * fn = strrchr(__zend_filename, PHP_DIR_SEPARATOR);
128+
DBG_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_filename, __zend_lineno);
129+
}
130+
#endif
121131

122132
#if PHP_DEBUG
123133
/* -1 is also "true" */
@@ -154,7 +164,12 @@ void * _mysqlnd_ecalloc(unsigned int nmemb, size_t size MYSQLND_MEM_D)
154164
long * threshold = &MYSQLND_G(debug_ecalloc_fail_threshold);
155165
#endif
156166
DBG_ENTER(mysqlnd_ecalloc_name);
157-
DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno);
167+
#if PHP_DEBUG
168+
{
169+
char * fn = strrchr(__zend_filename, PHP_DIR_SEPARATOR);
170+
DBG_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_filename, __zend_lineno);
171+
}
172+
#endif
158173
DBG_INF_FMT("before: %lu", zend_memory_usage(FALSE TSRMLS_CC));
159174

160175
#if PHP_DEBUG
@@ -189,7 +204,12 @@ void * _mysqlnd_pecalloc(unsigned int nmemb, size_t size, zend_bool persistent M
189204
long * threshold = persistent? &MYSQLND_G(debug_calloc_fail_threshold):&MYSQLND_G(debug_ecalloc_fail_threshold);
190205
#endif
191206
DBG_ENTER(mysqlnd_pecalloc_name);
192-
DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno);
207+
#if PHP_DEBUG
208+
{
209+
char * fn = strrchr(__zend_filename, PHP_DIR_SEPARATOR);
210+
DBG_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_filename, __zend_lineno);
211+
}
212+
#endif
193213

194214
#if PHP_DEBUG
195215
/* -1 is also "true" */
@@ -227,7 +247,12 @@ void * _mysqlnd_erealloc(void *ptr, size_t new_size MYSQLND_MEM_D)
227247
long * threshold = &MYSQLND_G(debug_erealloc_fail_threshold);
228248
#endif
229249
DBG_ENTER(mysqlnd_erealloc_name);
230-
DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno);
250+
#if PHP_DEBUG
251+
{
252+
char * fn = strrchr(__zend_filename, PHP_DIR_SEPARATOR);
253+
DBG_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_filename, __zend_lineno);
254+
}
255+
#endif
231256
DBG_INF_FMT("ptr=%p old_size=%lu, new_size=%lu", ptr, old_size, new_size);
232257

233258
#if PHP_DEBUG
@@ -262,7 +287,12 @@ void * _mysqlnd_perealloc(void *ptr, size_t new_size, zend_bool persistent MYSQL
262287
long * threshold = persistent? &MYSQLND_G(debug_realloc_fail_threshold):&MYSQLND_G(debug_erealloc_fail_threshold);
263288
#endif
264289
DBG_ENTER(mysqlnd_perealloc_name);
265-
DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno);
290+
#if PHP_DEBUG
291+
{
292+
char * fn = strrchr(__zend_filename, PHP_DIR_SEPARATOR);
293+
DBG_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_filename, __zend_lineno);
294+
}
295+
#endif
266296
DBG_INF_FMT("ptr=%p old_size=%lu new_size=%lu persistent=%u", ptr, old_size, new_size, persistent);
267297

268298
#if PHP_DEBUG
@@ -296,7 +326,12 @@ void _mysqlnd_efree(void *ptr MYSQLND_MEM_D)
296326
size_t free_amount = 0;
297327
zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics);
298328
DBG_ENTER(mysqlnd_efree_name);
299-
DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno);
329+
#if PHP_DEBUG
330+
{
331+
char * fn = strrchr(__zend_filename, PHP_DIR_SEPARATOR);
332+
DBG_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_filename, __zend_lineno);
333+
}
334+
#endif
300335
DBG_INF_FMT("ptr=%p", ptr);
301336

302337
if (ptr) {
@@ -321,7 +356,12 @@ void _mysqlnd_pefree(void *ptr, zend_bool persistent MYSQLND_MEM_D)
321356
size_t free_amount = 0;
322357
zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics);
323358
DBG_ENTER(mysqlnd_pefree_name);
324-
DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno);
359+
#if PHP_DEBUG
360+
{
361+
char * fn = strrchr(__zend_filename, PHP_DIR_SEPARATOR);
362+
DBG_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_filename, __zend_lineno);
363+
}
364+
#endif
325365
DBG_INF_FMT("ptr=%p persistent=%u", ptr, persistent);
326366

327367
if (ptr) {
@@ -349,7 +389,12 @@ void * _mysqlnd_malloc(size_t size MYSQLND_MEM_D)
349389
long * threshold = &MYSQLND_G(debug_malloc_fail_threshold);
350390
#endif
351391
DBG_ENTER(mysqlnd_malloc_name);
352-
DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno);
392+
#if PHP_DEBUG
393+
{
394+
char * fn = strrchr(__zend_filename, PHP_DIR_SEPARATOR);
395+
DBG_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_filename, __zend_lineno);
396+
}
397+
#endif
353398

354399
#if PHP_DEBUG
355400
/* -1 is also "true" */
@@ -382,7 +427,12 @@ void * _mysqlnd_calloc(unsigned int nmemb, size_t size MYSQLND_MEM_D)
382427
long * threshold = &MYSQLND_G(debug_calloc_fail_threshold);
383428
#endif
384429
DBG_ENTER(mysqlnd_calloc_name);
385-
DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno);
430+
#if PHP_DEBUG
431+
{
432+
char * fn = strrchr(__zend_filename, PHP_DIR_SEPARATOR);
433+
DBG_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_filename, __zend_lineno);
434+
}
435+
#endif
386436

387437
#if PHP_DEBUG
388438
/* -1 is also "true" */
@@ -415,7 +465,12 @@ void * _mysqlnd_realloc(void *ptr, size_t new_size MYSQLND_MEM_D)
415465
long * threshold = &MYSQLND_G(debug_realloc_fail_threshold);
416466
#endif
417467
DBG_ENTER(mysqlnd_realloc_name);
418-
DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno);
468+
#if PHP_DEBUG
469+
{
470+
char * fn = strrchr(__zend_filename, PHP_DIR_SEPARATOR);
471+
DBG_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_filename, __zend_lineno);
472+
}
473+
#endif
419474
DBG_INF_FMT("ptr=%p new_size=%lu ", new_size, ptr);
420475
DBG_INF_FMT("before: %lu", zend_memory_usage(TRUE TSRMLS_CC));
421476

@@ -448,7 +503,12 @@ void _mysqlnd_free(void *ptr MYSQLND_MEM_D)
448503
size_t free_amount = 0;
449504
zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics);
450505
DBG_ENTER(mysqlnd_free_name);
451-
DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno);
506+
#if PHP_DEBUG
507+
{
508+
char * fn = strrchr(__zend_filename, PHP_DIR_SEPARATOR);
509+
DBG_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_filename, __zend_lineno);
510+
}
511+
#endif
452512
DBG_INF_FMT("ptr=%p", ptr);
453513

454514
if (ptr) {
@@ -477,7 +537,12 @@ char * _mysqlnd_pestrndup(const char * const ptr, size_t length, zend_bool persi
477537
char * ret;
478538
zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics);
479539
DBG_ENTER(mysqlnd_pestrndup_name);
480-
DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno);
540+
#if PHP_DEBUG
541+
{
542+
char * fn = strrchr(__zend_filename, PHP_DIR_SEPARATOR);
543+
DBG_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_filename, __zend_lineno);
544+
}
545+
#endif
481546
DBG_INF_FMT("ptr=%p", ptr);
482547

483548
ret = pemalloc(REAL_SIZE(length) + 1, persistent);
@@ -509,7 +574,12 @@ char * _mysqlnd_pestrdup(const char * const ptr, zend_bool persistent MYSQLND_ME
509574
const char * p = ptr;
510575
zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics);
511576
DBG_ENTER(mysqlnd_pestrdup_name);
512-
DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno);
577+
#if PHP_DEBUG
578+
{
579+
char * fn = strrchr(__zend_filename, PHP_DIR_SEPARATOR);
580+
DBG_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_filename, __zend_lineno);
581+
}
582+
#endif
513583
DBG_INF_FMT("ptr=%p", ptr);
514584
do {
515585
smart_str_appendc(&tmp_str, *p);

0 commit comments

Comments
 (0)