summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnatol Belski <ab@php.net>2017-07-21 22:26:37 +0200
committerAnatol Belski <ab@php.net>2017-07-21 22:26:37 +0200
commit7ec8b8d49f42e6edf520324b202c5754cd6d9e90 (patch)
treeb75d669b83af5fd5857e54eba1846e67e780abd3
parentf8ffc9622ba3f9b9fbbf6d4357868d4e7901fa50 (diff)
downloadphp-git-7ec8b8d49f42e6edf520324b202c5754cd6d9e90.tar.gz
remove casts and ensure no out of bounds access
-rw-r--r--ext/standard/dl.c3
-rw-r--r--main/php_ini.c10
2 files changed, 8 insertions, 5 deletions
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 */