summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSara Golemon <pollita@php.net>2014-08-19 12:46:53 -0700
committerSara Golemon <pollita@php.net>2014-08-19 13:16:44 -0700
commitcbe1597b747474388912c91018b0e12275784720 (patch)
tree666128438228e1aebd7cb70aba1961049f5d1f7b
parent5a7039035ce22a68130af2309ff002a611976c87 (diff)
downloadphp-git-cbe1597b747474388912c91018b0e12275784720.tar.gz
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.
-rw-r--r--NEWS3
-rw-r--r--ext/gd/libgd/gdft.c6
2 files changed, 7 insertions, 2 deletions
diff --git a/NEWS b/NEWS
index f515bbe57c..5df40324da 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 ac2bf344ff..884a4148fe 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