-
Notifications
You must be signed in to change notification settings - Fork 7.9k
fix: used allocation without checking #9015
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: PHP-8.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2335,7 +2335,7 @@ static void zend_ffi_scope_hash_dtor(zval *zv) /* {{{ */ | |
zend_hash_destroy(scope->tags); | ||
free(scope->tags); | ||
} | ||
free(scope); | ||
pefree(scope, 1); | ||
} | ||
/* }}} */ | ||
|
||
|
@@ -3333,12 +3333,12 @@ static zend_ffi *zend_ffi_load(const char *filename, zend_bool preload) /* {{{ * | |
} | ||
|
||
if (!scope) { | ||
scope = malloc(sizeof(zend_ffi_scope)); | ||
scope = pemalloc(sizeof(zend_ffi_scope), 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you might need to mirror it in their freeing counterparts. |
||
scope->symbols = FFI_G(symbols); | ||
scope->tags = FFI_G(tags); | ||
|
||
if (!FFI_G(scopes)) { | ||
FFI_G(scopes) = malloc(sizeof(HashTable)); | ||
FFI_G(scopes) = pemalloc(sizeof(HashTable), 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto. |
||
zend_hash_init(FFI_G(scopes), 0, NULL, zend_ffi_scope_hash_dtor, 1); | ||
} | ||
|
||
|
@@ -5215,7 +5215,7 @@ static ZEND_GSHUTDOWN_FUNCTION(ffi) | |
{ | ||
if (ffi_globals->scopes) { | ||
zend_hash_destroy(ffi_globals->scopes); | ||
free(ffi_globals->scopes); | ||
pefree(ffi_globals->scopes, 1); | ||
} | ||
zend_hash_destroy(&ffi_globals->types); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -255,10 +255,10 @@ static void fcgi_hash_init(fcgi_hash *h) | |
{ | ||
memset(h->hash_table, 0, sizeof(h->hash_table)); | ||
h->list = NULL; | ||
h->buckets = (fcgi_hash_buckets*)malloc(sizeof(fcgi_hash_buckets)); | ||
h->buckets = (fcgi_hash_buckets*)pemalloc(sizeof(fcgi_hash_buckets), 1); | ||
h->buckets->idx = 0; | ||
h->buckets->next = NULL; | ||
h->data = (fcgi_data_seg*)malloc(sizeof(fcgi_data_seg) - 1 + FCGI_HASH_SEG_SIZE); | ||
h->data = (fcgi_data_seg*)pemalloc(sizeof(fcgi_data_seg) - 1 + FCGI_HASH_SEG_SIZE, 1); | ||
h->data->pos = h->data->data; | ||
h->data->end = h->data->pos + FCGI_HASH_SEG_SIZE; | ||
h->data->next = NULL; | ||
|
@@ -273,13 +273,13 @@ static void fcgi_hash_destroy(fcgi_hash *h) | |
while (b) { | ||
fcgi_hash_buckets *q = b; | ||
b = b->next; | ||
free(q); | ||
pefree(q, 1); | ||
} | ||
p = h->data; | ||
while (p) { | ||
fcgi_data_seg *q = p; | ||
p = p->next; | ||
free(q); | ||
pefree(q, 1); | ||
} | ||
} | ||
|
||
|
@@ -292,15 +292,15 @@ static void fcgi_hash_clean(fcgi_hash *h) | |
fcgi_hash_buckets *q = h->buckets; | ||
|
||
h->buckets = h->buckets->next; | ||
free(q); | ||
pefree(q, 1); | ||
} | ||
h->buckets->idx = 0; | ||
/* delete all data segments except the first one */ | ||
while (h->data->next) { | ||
fcgi_data_seg *q = h->data; | ||
|
||
h->data = h->data->next; | ||
free(q); | ||
pefree(q, 1); | ||
} | ||
h->data->pos = h->data->data; | ||
} | ||
|
@@ -311,7 +311,7 @@ static inline char* fcgi_hash_strndup(fcgi_hash *h, char *str, unsigned int str_ | |
|
||
if (UNEXPECTED(h->data->pos + str_len + 1 >= h->data->end)) { | ||
unsigned int seg_size = (str_len + 1 > FCGI_HASH_SEG_SIZE) ? str_len + 1 : FCGI_HASH_SEG_SIZE; | ||
fcgi_data_seg *p = (fcgi_data_seg*)malloc(sizeof(fcgi_data_seg) - 1 + seg_size); | ||
fcgi_data_seg *p = (fcgi_data_seg*)pemalloc(sizeof(fcgi_data_seg) - 1 + seg_size, 1); | ||
|
||
p->pos = p->data; | ||
p->end = p->pos + seg_size; | ||
|
@@ -343,7 +343,7 @@ static char* fcgi_hash_set(fcgi_hash *h, unsigned int hash_value, char *var, uns | |
} | ||
|
||
if (UNEXPECTED(h->buckets->idx >= FCGI_HASH_TABLE_SIZE)) { | ||
fcgi_hash_buckets *b = (fcgi_hash_buckets*)malloc(sizeof(fcgi_hash_buckets)); | ||
fcgi_hash_buckets *b = (fcgi_hash_buckets*)pemalloc(sizeof(fcgi_hash_buckets), 1); | ||
b->idx = 0; | ||
b->next = h->buckets; | ||
h->buckets = b; | ||
|
@@ -561,7 +561,8 @@ void fcgi_shutdown(void) | |
} | ||
is_fastcgi = 0; | ||
if (allowed_clients) { | ||
free(allowed_clients); | ||
pefree(allowed_clients, 1); | ||
allowed_clients = NULL; | ||
} | ||
} | ||
|
||
|
@@ -769,45 +770,9 @@ int fcgi_listen(const char *path, int backlog) | |
chmod(path, 0777); | ||
} else { | ||
char *ip = getenv("FCGI_WEB_SERVER_ADDRS"); | ||
char *cur, *end; | ||
int n; | ||
|
||
if (ip) { | ||
ip = strdup(ip); | ||
cur = ip; | ||
n = 0; | ||
while (*cur) { | ||
if (*cur == ',') n++; | ||
cur++; | ||
} | ||
allowed_clients = malloc(sizeof(sa_t) * (n+2)); | ||
n = 0; | ||
cur = ip; | ||
while (cur) { | ||
end = strchr(cur, ','); | ||
if (end) { | ||
*end = 0; | ||
end++; | ||
} | ||
if (inet_pton(AF_INET, cur, &allowed_clients[n].sa_inet.sin_addr)>0) { | ||
allowed_clients[n].sa.sa_family = AF_INET; | ||
n++; | ||
#ifdef HAVE_IPV6 | ||
} else if (inet_pton(AF_INET6, cur, &allowed_clients[n].sa_inet6.sin6_addr)>0) { | ||
allowed_clients[n].sa.sa_family = AF_INET6; | ||
n++; | ||
#endif | ||
} else { | ||
fcgi_log(FCGI_ERROR, "Wrong IP address '%s' in listen.allowed_clients", cur); | ||
} | ||
cur = end; | ||
} | ||
allowed_clients[n].sa.sa_family = 0; | ||
free(ip); | ||
if (!n) { | ||
fcgi_log(FCGI_ERROR, "There are no allowed addresses"); | ||
/* don't clear allowed_clients as it will create an "open for all" security issue */ | ||
} | ||
fcgi_set_allowed_clients(ip); | ||
} | ||
} | ||
|
||
|
@@ -826,23 +791,23 @@ int fcgi_listen(const char *path, int backlog) | |
return listen_socket; | ||
} | ||
|
||
void fcgi_set_allowed_clients(char *ip) | ||
void fcgi_set_allowed_clients(const char *ip) | ||
{ | ||
char *cur, *end; | ||
int n; | ||
|
||
if (ip) { | ||
ip = strdup(ip); | ||
cur = ip; | ||
char *dup_ip = estrdup(ip); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From what I can see this functions is called from |
||
cur = dup_ip; | ||
n = 0; | ||
while (*cur) { | ||
if (*cur == ',') n++; | ||
cur++; | ||
} | ||
if (allowed_clients) free(allowed_clients); | ||
allowed_clients = malloc(sizeof(sa_t) * (n+2)); | ||
if (allowed_clients) pefree(allowed_clients, 1); | ||
allowed_clients = safe_pemalloc(sizeof(sa_t), n+2, 0, 1); | ||
n = 0; | ||
cur = ip; | ||
cur = dup_ip; | ||
while (cur) { | ||
end = strchr(cur, ','); | ||
if (end) { | ||
|
@@ -863,7 +828,7 @@ void fcgi_set_allowed_clients(char *ip) | |
cur = end; | ||
} | ||
allowed_clients[n].sa.sa_family = 0; | ||
free(ip); | ||
efree(dup_ip); | ||
if (!n) { | ||
fcgi_log(FCGI_ERROR, "There are no allowed addresses"); | ||
/* don't clear allowed_clients as it will create an "open for all" security issue */ | ||
|
@@ -877,7 +842,7 @@ static void fcgi_hook_dummy() { | |
|
||
fcgi_request *fcgi_init_request(int listen_socket, void(*on_accept)(), void(*on_read)(), void(*on_close)()) | ||
{ | ||
fcgi_request *req = calloc(1, sizeof(fcgi_request)); | ||
fcgi_request *req = pecalloc(1, sizeof(fcgi_request), 1); | ||
req->listen_socket = listen_socket; | ||
req->fd = -1; | ||
req->id = -1; | ||
|
@@ -912,7 +877,7 @@ fcgi_request *fcgi_init_request(int listen_socket, void(*on_accept)(), void(*on_ | |
|
||
void fcgi_destroy_request(fcgi_request *req) { | ||
fcgi_hash_destroy(&req->env); | ||
free(req); | ||
pefree(req, 1); | ||
} | ||
|
||
static inline ssize_t safe_write(fcgi_request *req, const void *buf, size_t count) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -758,12 +758,12 @@ static void sapi_cgi_log_message(const char *message, int syslog_type_int) | |
request = (fcgi_request*) SG(server_context); | ||
if (request) { | ||
int ret, len = (int)strlen(message); | ||
char *buf = malloc(len+2); | ||
|
||
char *buf = pemalloc(len+2, 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, this can be called outside of request context. |
||
memcpy(buf, message, len); | ||
memcpy(buf + len, "\n", sizeof("\n")); | ||
ret = fcgi_write(request, FCGI_STDERR, buf, (int)(len + 1)); | ||
free(buf); | ||
pefree(buf, 0); | ||
if (ret < 0) { | ||
php_handle_aborted_connection(); | ||
} | ||
|
@@ -1801,15 +1801,16 @@ int main(int argc, char *argv[]) | |
if((query_string = getenv("QUERY_STRING")) != NULL && strchr(query_string, '=') == NULL) { | ||
/* we've got query string that has no = - apache CGI will pass it to command line */ | ||
unsigned char *p; | ||
decoded_query_string = strdup(query_string); | ||
|
||
decoded_query_string = pestrdup(query_string, 0); | ||
php_url_decode(decoded_query_string, strlen(decoded_query_string)); | ||
for (p = (unsigned char *)decoded_query_string; *p && *p <= ' '; p++) { | ||
/* skip all leading spaces */ | ||
} | ||
if(*p == '-') { | ||
skip_getopt = 1; | ||
} | ||
free(decoded_query_string); | ||
pefree(decoded_query_string, 0); | ||
} | ||
|
||
while (!skip_getopt && (c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) { | ||
|
@@ -2438,7 +2439,7 @@ consult the installation file that came with this distribution, or visit \n\ | |
} | ||
|
||
len += 2; | ||
s = malloc(len); | ||
s = pemalloc(len, 0); | ||
*s = '\0'; /* we are pretending it came from the environment */ | ||
for (i = php_optind; i < argc; i++) { | ||
strlcat(s, argv[i], len); | ||
|
@@ -2507,7 +2508,7 @@ consult the installation file that came with this distribution, or visit \n\ | |
} | ||
|
||
if (free_query_string && SG(request_info).query_string) { | ||
free(SG(request_info).query_string); | ||
pefree(SG(request_info).query_string, 0); | ||
SG(request_info).query_string = NULL; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be persistent.
ht
is later stored inEXIF_G(tag_table_cache)
which lives beyond requests, as far as I can see.