From: Anatol Belski Date: Fri, 21 Jul 2017 20:26:37 +0000 (+0200) Subject: remove casts and ensure no out of bounds access X-Git-Tag: php-7.2.0beta2~80 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7ec8b8d49f42e6edf520324b202c5754cd6d9e90;p=php remove casts and ensure no out of bounds access --- diff --git a/ext/standard/dl.c b/ext/standard/dl.c index 1739648ffa..f7407927a9 100644 --- a/ext/standard/dl.c +++ b/ext/standard/dl.c @@ -135,8 +135,7 @@ PHPAPI int php_load_extension(char *filename, int type, int start_now) } libpath = estrdup(filename); } else if (extension_dir && extension_dir[0]) { - int extension_dir_len = (int)strlen(extension_dir); - slash_suffix = IS_SLASH(extension_dir[extension_dir_len-1]); + slash_suffix = IS_SLASH(extension_dir[strlen(extension_dir)-1]); /* Try as filename first */ if (slash_suffix) { spprintf(&libpath, 0, "%s%s", extension_dir, filename); /* SAFE */ diff --git a/main/php_ini.c b/main/php_ini.c index 4e013c8aca..7b0375027d 100644 --- a/main/php_ini.c +++ b/main/php_ini.c @@ -353,7 +353,7 @@ static void php_load_php_extension_cb(void *arg) static void php_load_zend_extension_cb(void *arg) { char *filename = *((char **) arg); - const int length = (int)strlen(filename); + const size_t length = strlen(filename); #ifndef PHP_WIN32 (void) length; @@ -365,9 +365,13 @@ static void php_load_zend_extension_cb(void *arg) DL_HANDLE handle; char *libpath; char *extension_dir = INI_STR("extension_dir"); - int extension_dir_len = (int)strlen(extension_dir); - int slash_suffix = IS_SLASH(extension_dir[extension_dir_len-1]); + int slash_suffix = 0; char *err1, *err2; + + if (extension_dir && extension_dir[0]) { + slash_suffix = IS_SLASH(extension_dir[strlen(extension_dir)-1]); + } + /* Try as filename first */ if (slash_suffix) { spprintf(&libpath, 0, "%s%s", extension_dir, filename); /* SAFE */