From cbe1597b747474388912c91018b0e12275784720 Mon Sep 17 00:00:00 2001 From: Sara Golemon Date: Tue, 19 Aug 2014 12:46:53 -0700 Subject: [PATCH] Switch use of strtok() to gd_strtok_r() strtok() is not thread safe, so this will potentially break in very bad ways if used in ZTS mode. I'm not sure why gd_strtok_r() exists since it seems to do the same thing as strtok_r(), but I'll assume it's a portability decision and do as the Romans do. --- NEWS | 3 +++ ext/gd/libgd/gdft.c | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index f515bbe57c7..5df40324da6 100644 --- a/NEWS +++ b/NEWS @@ -12,6 +12,9 @@ PHP NEWS - Date: . Fixed bug #66091 (memory leaks in DateTime constructor). (Tjerk). +- GD + . Made fontFetch's path parser thread-safe. (Sara). + ?? ??? 2014, PHP 5.4.32 - COM: diff --git a/ext/gd/libgd/gdft.c b/ext/gd/libgd/gdft.c index ac2bf344ffe..884a4148fe8 100644 --- a/ext/gd/libgd/gdft.c +++ b/ext/gd/libgd/gdft.c @@ -370,9 +370,10 @@ static void *fontFetch (char **error, void *key) fontlist = gdEstrdup(a->fontlist); /* - * Must use gd_strtok_r else pointer corrupted by strtok in nested loop. + * Must use gd_strtok_r becasuse strtok() isn't thread safe */ for (name = gd_strtok_r (fontlist, LISTSEPARATOR, &strtok_ptr); name; name = gd_strtok_r (0, LISTSEPARATOR, &strtok_ptr)) { + char *strtok_ptr_path; /* make a fresh copy each time - strtok corrupts it. */ path = gdEstrdup (fontsearchpath); @@ -388,7 +389,8 @@ static void *fontFetch (char **error, void *key) break; } } - for (dir = strtok (path, PATHSEPARATOR); dir; dir = strtok (0, PATHSEPARATOR)) { + for (dir = gd_strtok_r (path, PATHSEPARATOR, &strtok_ptr_path); dir; + dir = gd_strtok_r (0, PATHSEPARATOR, &strtok_ptr_path)) { if (!strcmp(dir, ".")) { TSRMLS_FETCH(); #if HAVE_GETCWD