From a1201785208cc953ed0d9bd793976ab722848649 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Mon, 18 Feb 2013 11:34:10 +0400 Subject: [PATCH] Added checks for malloc() failures --- ZendAccelerator.c | 12 ++++++++++++ zend_accelerator_blacklist.c | 17 ++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/ZendAccelerator.c b/ZendAccelerator.c index 5a0f1cef0a..033c7af940 100644 --- a/ZendAccelerator.c +++ b/ZendAccelerator.c @@ -1475,6 +1475,10 @@ static char *accel_tsrm_realpath(const char *path, int path_len TSRMLS_DC) /* realpath("") returns CWD */ if (!*path) { new_state.cwd = (char*)malloc(1); + if (!new_state.cwd) { + zend_accel_error(ACCEL_LOG_ERROR, "malloc() failed"); + return NULL; + } new_state.cwd[0] = '\0'; new_state.cwd_length = 0; if ((cwd = accel_getcwd(&cwd_len TSRMLS_CC)) != NULL) { @@ -1483,9 +1487,17 @@ static char *accel_tsrm_realpath(const char *path, int path_len TSRMLS_DC) } else if (!IS_ABSOLUTE_PATH(path, path_len) && (cwd = accel_getcwd(&cwd_len TSRMLS_CC)) != NULL) { new_state.cwd = zend_strndup(cwd, cwd_len); + if (!new_state.cwd) { + zend_accel_error(ACCEL_LOG_ERROR, "malloc() failed"); + return NULL; + } new_state.cwd_length = cwd_len; } else { new_state.cwd = (char*)malloc(1); + if (!new_state.cwd) { + zend_accel_error(ACCEL_LOG_ERROR, "malloc() failed"); + return NULL; + } new_state.cwd[0] = '\0'; new_state.cwd_length = 0; } diff --git a/zend_accelerator_blacklist.c b/zend_accelerator_blacklist.c index 7ceadeacf3..52f4216a64 100644 --- a/zend_accelerator_blacklist.c +++ b/zend_accelerator_blacklist.c @@ -63,7 +63,10 @@ static void blacklist_report_regexp_error(regex_t *comp_regex, int reg_err) char *errbuf; int errsize = regerror(reg_err, comp_regex, NULL, 0); errbuf = malloc(errsize); - + if (!errbuf) { + zend_accel_error(ACCEL_LOG_ERROR, "Blacklist compilation: no memory\n"); + return; + } regerror(reg_err, comp_regex, errbuf, errsize); zend_accel_error(ACCEL_LOG_ERROR, "Blacklist compilation: %s\n", errbuf); free(errbuf); @@ -87,6 +90,10 @@ static void zend_accel_blacklist_update_regexp(zend_blacklist *blacklist) /* don't create a regexp buffer bigger than 12K)*/ if((i+1 == blacklist->pos) || ((rlen+blacklist->entries[i+1].path_length*2+2)>(12*1024) ) ) { regexp = (char *)malloc(rlen); + if (!regexp) { + zend_accel_error(ACCEL_LOG_ERROR, "malloc() failed\n"); + return; + } regexp[0] = '^'; regexp[1] = '('; @@ -109,6 +116,10 @@ static void zend_accel_blacklist_update_regexp(zend_blacklist *blacklist) regexp[clen] = '\0'; (*regexp_list_it) = malloc(sizeof(zend_regexp_list)); + if (!*regexp_list_it) { + zend_accel_error(ACCEL_LOG_ERROR, "malloc() failed\n"); + return; + } (*regexp_list_it)->next = NULL; if ((reg_err = regcomp(&((*regexp_list_it)->comp_regex), regexp, REGEX_MODE)) != 0) { @@ -205,6 +216,10 @@ void zend_accel_blacklist_load(zend_blacklist *blacklist, char *filename) zend_accel_blacklist_allocate(blacklist); blacklist->entries[blacklist->pos].path_length = path_length; blacklist->entries[blacklist->pos].path = (char *) malloc(path_length+1); + if (!blacklist->entries[blacklist->pos].path) { + zend_accel_error(ACCEL_LOG_ERROR, "malloc() failed\n"); + return; + } blacklist->entries[blacklist->pos].id = blacklist->pos; memcpy(blacklist->entries[blacklist->pos].path, real_path, path_length+1); blacklist->pos++; -- 2.40.0