]> granicus.if.org Git - php/commitdiff
fix a very rare case of use of uninitialized value combined with a
authorMichael Wallner <mike@php.net>
Wed, 18 Sep 2013 09:10:55 +0000 (11:10 +0200)
committerMichael Wallner <mike@php.net>
Wed, 18 Sep 2013 09:10:55 +0000 (11:10 +0200)
memleak

main/fopen_wrappers.c

index 6f11cf3f3254b841e04309ad4ea99abd2b461d4f..9b8645a061e7ec3b3fdf49638e55f35ed9b3d0b2 100644 (file)
@@ -775,7 +775,12 @@ PHPAPI char *expand_filepath_with_mode(const char *filepath, char *real_path, co
                                 * we cannot cannot getcwd() and the requested,
                                 * relatively referenced file is accessible */
                                copy_len = strlen(filepath) > MAXPATHLEN - 1 ? MAXPATHLEN - 1 : strlen(filepath);
-                               real_path = estrndup(filepath, copy_len);
+                               if (real_path) {
+                                       memcpy(real_path, filepath, copy_len);
+                                       real_path[copy_len] = '\0';
+                               } else {
+                                       real_path = estrndup(filepath, copy_len);
+                               }
                                close(fdtest);
                                return real_path;
                        } else {