Skip to content

Instantly share code, notes, and snippets.

/73189.diff Secret

Created September 29, 2016 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/3e01bddbd191da28ccb441bbe726b0f5 to your computer and use it in GitHub Desktop.
Save anonymous/3e01bddbd191da28ccb441bbe726b0f5 to your computer and use it in GitHub Desktop.
Patch for 73189
commit da7e89cde880c66887caacd0a3eae7ecdacf9b2a
Author: Stanislav Malyshev <stas@php.net>
Date: Wed Sep 28 23:30:48 2016 -0700
Fix bug #73189 - Memcpy negative size parameter php_resolve_path
diff --git a/main/fopen_wrappers.c b/main/fopen_wrappers.c
index 74a493b..af9c558 100644
--- a/main/fopen_wrappers.c
+++ b/main/fopen_wrappers.c
@@ -522,7 +522,7 @@ PHPAPI char *php_resolve_path(const char *filename, int filename_length, const c
}
end = strchr(p, DEFAULT_DIR_SEPARATOR);
if (end) {
- if ((end-ptr) + 1 + filename_length + 1 >= MAXPATHLEN) {
+ if (filename_length > (MAXPATHLEN - 2) || (end-ptr) > MAXPATHLEN || (end-ptr) + 1 + (size_t)filename_length + 1 >= MAXPATHLEN) {
ptr = end + 1;
continue;
}
@@ -531,9 +531,9 @@ PHPAPI char *php_resolve_path(const char *filename, int filename_length, const c
memcpy(trypath+(end-ptr)+1, filename, filename_length+1);
ptr = end+1;
} else {
- int len = strlen(ptr);
+ size_t len = strlen(ptr);
- if (len + 1 + filename_length + 1 >= MAXPATHLEN) {
+ if (filename_length > (MAXPATHLEN - 2) || len > MAXPATHLEN || (size_t)len + 1 + (size_t)filename_length + 1 >= MAXPATHLEN) {
break;
}
memcpy(trypath, ptr, len);
@@ -571,6 +571,7 @@ PHPAPI char *php_resolve_path(const char *filename, int filename_length, const c
while ((--exec_fname_length >= 0) && !IS_SLASH(exec_fname[exec_fname_length]));
if (exec_fname && exec_fname[0] != '[' &&
exec_fname_length > 0 &&
+ filename_length < (MAXPATHLEN - 2) &&
exec_fname_length + 1 + filename_length + 1 < MAXPATHLEN) {
memcpy(trypath, exec_fname, exec_fname_length + 1);
memcpy(trypath+exec_fname_length + 1, filename, filename_length+1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment