iliaa           Mon Dec 15 15:34:48 2003 EDT

  Modified files:              
    /php-src/ext/gd/libgd       gdft.c 
  Log:
  Fixed bug #26635 (fixed look up for fonts in the current directory w/ZTS)
  
  
Index: php-src/ext/gd/libgd/gdft.c
diff -u php-src/ext/gd/libgd/gdft.c:1.24 php-src/ext/gd/libgd/gdft.c:1.25
--- php-src/ext/gd/libgd/gdft.c:1.24    Tue Jun 17 09:37:43 2003
+++ php-src/ext/gd/libgd/gdft.c Mon Dec 15 15:34:48 2003
@@ -357,7 +357,7 @@
        int font_found = 0;
        unsigned short platform, encoding;
        char *fontsearchpath, *fontlist;
-       char *fullname = NULL;
+       char fullname[MAXPATHLEN], cur_dir[MAXPATHLEN];
        char *name, *path=NULL, *dir;
        char *strtok_ptr;
        FT_Error err;
@@ -383,38 +383,43 @@
        for (name = gd_strtok_r (fontlist, LISTSEPARATOR, &strtok_ptr); name; name = 
gd_strtok_r (0, LISTSEPARATOR, &strtok_ptr)) {
                /* make a fresh copy each time - strtok corrupts it. */
                path = gdEstrdup (fontsearchpath);
-       
-               /*
-               * Allocate an oversized buffer that is guaranteed to be
-               * big enough for all paths to be tested.
-               */
-               fullname = gdRealloc (fullname, strlen (fontsearchpath) + strlen 
(name) + 6);
-       
+
                /* if name is an absolute filename then test directly */ 
                if (*name == '/' || (name[0] != 0 && name[1] == ':' && (name[2] == '/' 
|| name[2] == '\\'))) {
-                       sprintf(fullname, "%s", name);
+                       snprintf(fullname, sizeof(fullname) - 1, "%s", name);
                        if (access(fullname, R_OK) == 0) {
                                font_found++;
                                break;
                        }
                }
                for (dir = strtok (path, PATHSEPARATOR); dir; dir = strtok (0, 
PATHSEPARATOR)) {
-                       sprintf(fullname, "%s/%s", dir, name);
-                       if (access (fullname, R_OK) == 0) {
+                       if (!strcmp(dir, ".")) {
+#if HAVE_GETCWD
+                               dir = VCWD_GETCWD(cur_dir, MAXPATHLEN);
+#elif HAVE_GETWD
+                               dir = VCWD_GETWD(cur_dir);
+#endif
+                               if (!dir) {
+                                       continue;
+                               }
+                       }
+
+                       snprintf(fullname, sizeof(fullname) - 1, "%s/%s", dir, name);
+                       if (access(fullname, R_OK) == 0) {
                                font_found++;
                                break;
                        }
-                       sprintf(fullname, "%s/%s.ttf", dir, name);
-                       if (access (fullname, R_OK) == 0) {
+                       snprintf(fullname, sizeof(fullname) - 1, "%s/%s.ttf", dir, 
name);
+                       if (access(fullname, R_OK) == 0) {
                                font_found++;
                                break;
                        }
-                       sprintf(fullname, "%s/%s.pfa", dir, name);
+                       snprintf(fullname, sizeof(fullname) - 1, "%s/%s.pfa", dir, 
name);
                        if (access(fullname, R_OK) == 0) {
                                font_found++;
                                break;
                        }
-                       sprintf (fullname, "%s/%s.pfb", dir, name);
+                       snprintf(fullname, sizeof(fullname) - 1, "%s/%s.pfb", dir, 
name);
                        if (access(fullname, R_OK) == 0) {
                                font_found++;
                                break;
@@ -436,9 +441,6 @@
        if (!font_found) {
                gdPFree(a->fontlist);
                gdPFree(a);
-               if (fullname) {
-                       gdFree(fullname);
-               }
                *error = "Could not find/open font";
                return NULL;
        }
@@ -447,13 +449,9 @@
        if (err) {
                gdPFree(a->fontlist);
                gdPFree(a);
-               if (fullname) {
-                       gdFree(fullname);
-               }
                *error = "Could not read font";
                return NULL;
        }
-       gdFree(fullname);
 
        /* FIXME - This mapping stuff is imcomplete - where is the spec? */
 

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to