Skip to content

Commit 9bfd55c

Browse files
committed
fix a very rare case of use of uninitialized value combined with a
memleak
1 parent dfd7d10 commit 9bfd55c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

main/fopen_wrappers.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,12 @@ PHPAPI char *expand_filepath_with_mode(const char *filepath, char *real_path, co
775775
* we cannot cannot getcwd() and the requested,
776776
* relatively referenced file is accessible */
777777
copy_len = strlen(filepath) > MAXPATHLEN - 1 ? MAXPATHLEN - 1 : strlen(filepath);
778-
real_path = estrndup(filepath, copy_len);
778+
if (real_path) {
779+
memcpy(real_path, filepath, copy_len);
780+
real_path[copy_len] = '\0';
781+
} else {
782+
real_path = estrndup(filepath, copy_len);
783+
}
779784
close(fdtest);
780785
return real_path;
781786
} else {

0 commit comments

Comments
 (0)