mirror of
https://github.com/php/php-src.git
synced 2025-08-18 15:08:55 +02:00
Fixed bug #39623 (thread safety fixes on *nix for putenv() & mime_magic).
This commit is contained in:
parent
f06eb4bf8b
commit
e6a3431315
2 changed files with 5 additions and 4 deletions
|
@ -1388,6 +1388,7 @@ static int ascmagic(unsigned char *buf, int nbytes)
|
|||
char *token;
|
||||
register struct names *p;
|
||||
int small_nbytes;
|
||||
char *strtok_buf = NULL;
|
||||
|
||||
/* these are easy, do them first */
|
||||
|
||||
|
@ -1420,8 +1421,7 @@ static int ascmagic(unsigned char *buf, int nbytes)
|
|||
s = (unsigned char *) memcpy(nbuf, buf, small_nbytes);
|
||||
s[small_nbytes] = '\0';
|
||||
has_escapes = (memchr(s, '\033', small_nbytes) != NULL);
|
||||
/* XXX: not multithread safe */
|
||||
while ((token = strtok((char *) s, " \t\n\r\f")) != NULL) {
|
||||
while ((token = php_strtok_r((char *) s, " \t\n\r\f", &strtok_buf)) != NULL) {
|
||||
s = NULL; /* make strtok() keep on tokin' */
|
||||
for (p = names; p < names + NNAMES; p++) {
|
||||
if (STREQ(p->name, token)) {
|
||||
|
|
|
@ -4398,7 +4398,8 @@ PHP_FUNCTION(putenv)
|
|||
/* Check the allowed list */
|
||||
if (BG(sm_allowed_env_vars) && *BG(sm_allowed_env_vars)) {
|
||||
char *allowed_env_vars = estrdup(BG(sm_allowed_env_vars));
|
||||
char *allowed_prefix = strtok(allowed_env_vars, ", ");
|
||||
char *strtok_buf = NULL;
|
||||
char *allowed_prefix = php_strtok_r(allowed_env_vars, ", ", &strtok_buf);
|
||||
zend_bool allowed = 0;
|
||||
|
||||
while (allowed_prefix) {
|
||||
|
@ -4406,7 +4407,7 @@ PHP_FUNCTION(putenv)
|
|||
allowed = 1;
|
||||
break;
|
||||
}
|
||||
allowed_prefix = strtok(NULL, ", ");
|
||||
allowed_prefix = php_strtok_r(NULL, ", ", &strtok_buf);
|
||||
}
|
||||
efree(allowed_env_vars);
|
||||
if (!allowed) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue