Skip to content

Commit 8bc8271

Browse files
committed
Merge branch 'PHP-5.4' into PHP-5.5
* PHP-5.4: Fix #66942: openssl_seal() memory leak ws fix Conflicts: ext/openssl/openssl.c
2 parents 22acea9 + a186312 commit 8bc8271

File tree

3 files changed

+31
-24
lines changed

3 files changed

+31
-24
lines changed

NEWS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,17 @@ PHP NEWS
3535
. Fixed bug #66021 (Blank line inside empty array/object when
3636
JSON_PRETTY_PRINT is set). (Kevin Israel)
3737

38+
- LDAP:
39+
. Fixed issue with null bytes in LDAP bindings. (Matthew Daley)
40+
3841
- mysqli:
3942
. Fixed problem in mysqli_commit()/mysqli_rollback() with second parameter
4043
(extra comma) and third parameters (lack of escaping). (Andrey)
4144

45+
- OpenSSL:
46+
. Fix bug #66942 (memory leak in openssl_seal()). (Chuan Ma)
47+
. Fix bug #66952 (memory leak in openssl_open()). (Chuan Ma)
48+
4249
- SimpleXML:
4350
. Fixed bug #66084 (simplexml_load_string() mangles empty node name)
4451
(Anatol)

ext/openssl/openssl.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4384,6 +4384,7 @@ PHP_FUNCTION(openssl_seal)
43844384

43854385
if (!EVP_EncryptInit(&ctx,cipher,NULL,NULL)) {
43864386
RETVAL_FALSE;
4387+
EVP_CIPHER_CTX_cleanup(&ctx);
43874388
goto clean_exit;
43884389
}
43894390

@@ -4394,10 +4395,12 @@ PHP_FUNCTION(openssl_seal)
43944395
#endif
43954396
/* allocate one byte extra to make room for \0 */
43964397
buf = emalloc(data_len + EVP_CIPHER_CTX_block_size(&ctx));
4398+
EVP_CIPHER_CTX_cleanup(&ctx);
43974399

43984400
if (!EVP_SealInit(&ctx, cipher, eks, eksl, NULL, pkeys, nkeys) || !EVP_SealUpdate(&ctx, buf, &len1, (unsigned char *)data, data_len)) {
43994401
RETVAL_FALSE;
44004402
efree(buf);
4403+
EVP_CIPHER_CTX_cleanup(&ctx);
44014404
goto clean_exit;
44024405
}
44034406

@@ -4430,6 +4433,7 @@ PHP_FUNCTION(openssl_seal)
44304433
efree(buf);
44314434
}
44324435
RETVAL_LONG(len1 + len2);
4436+
EVP_CIPHER_CTX_cleanup(&ctx);
44334437

44344438
clean_exit:
44354439
for (i=0; i<nkeys; i++) {
@@ -4488,25 +4492,21 @@ PHP_FUNCTION(openssl_open)
44884492
if (EVP_OpenInit(&ctx, cipher, (unsigned char *)ekey, ekey_len, NULL, pkey) && EVP_OpenUpdate(&ctx, buf, &len1, (unsigned char *)data, data_len)) {
44894493
if (!EVP_OpenFinal(&ctx, buf + len1, &len2) || (len1 + len2 == 0)) {
44904494
efree(buf);
4491-
if (keyresource == -1) {
4492-
EVP_PKEY_free(pkey);
4493-
}
4494-
RETURN_FALSE;
4495+
RETVAL_FALSE;
4496+
} else {
4497+
zval_dtor(opendata);
4498+
buf[len1 + len2] = '\0';
4499+
ZVAL_STRINGL(opendata, erealloc(buf, len1 + len2 + 1), len1 + len2, 0);
4500+
RETVAL_TRUE;
44954501
}
44964502
} else {
44974503
efree(buf);
4498-
if (keyresource == -1) {
4499-
EVP_PKEY_free(pkey);
4500-
}
4501-
RETURN_FALSE;
4504+
RETVAL_FALSE;
45024505
}
45034506
if (keyresource == -1) {
45044507
EVP_PKEY_free(pkey);
45054508
}
4506-
zval_dtor(opendata);
4507-
buf[len1 + len2] = '\0';
4508-
ZVAL_STRINGL(opendata, erealloc(buf, len1 + len2 + 1), len1 + len2, 0);
4509-
RETURN_TRUE;
4509+
EVP_CIPHER_CTX_cleanup(&ctx);
45104510
}
45114511
/* }}} */
45124512

ext/session/mod_files.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -136,27 +136,27 @@ static void ps_files_open(ps_files *data, const char *key TSRMLS_DC)
136136

137137
data->lastkey = estrdup(key);
138138

139-
/* O_NOFOLLOW to prevent us from following evil symlinks */
139+
/* O_NOFOLLOW to prevent us from following evil symlinks */
140140
#ifdef O_NOFOLLOW
141-
data->fd = VCWD_OPEN_MODE(buf, O_CREAT | O_RDWR | O_BINARY | O_NOFOLLOW, data->filemode);
141+
data->fd = VCWD_OPEN_MODE(buf, O_CREAT | O_RDWR | O_BINARY | O_NOFOLLOW, data->filemode);
142142
#else
143-
/* Check to make sure that the opened file is not outside of allowable dirs.
144-
This is not 100% safe but it's hard to do something better without O_NOFOLLOW */
145-
if(PG(open_basedir) && lstat(buf, &sbuf) == 0 && S_ISLNK(sbuf.st_mode) && php_check_open_basedir(buf TSRMLS_CC)) {
146-
return;
147-
}
148-
data->fd = VCWD_OPEN_MODE(buf, O_CREAT | O_RDWR | O_BINARY, data->filemode);
143+
/* Check to make sure that the opened file is not outside of allowable dirs.
144+
This is not 100% safe but it's hard to do something better without O_NOFOLLOW */
145+
if(PG(open_basedir) && lstat(buf, &sbuf) == 0 && S_ISLNK(sbuf.st_mode) && php_check_open_basedir(buf TSRMLS_CC)) {
146+
return;
147+
}
148+
data->fd = VCWD_OPEN_MODE(buf, O_CREAT | O_RDWR | O_BINARY, data->filemode);
149149
#endif
150150

151151
if (data->fd != -1) {
152152
#ifndef PHP_WIN32
153-
/* check that this session file was created by us or root – we
154-
don't want to end up accepting the sessions of another webapp */
155-
if (fstat(data->fd, &sbuf) || (sbuf.st_uid != 0 && sbuf.st_uid != getuid() && sbuf.st_uid != geteuid())) {
153+
/* check that this session file was created by us or root – we
154+
don't want to end up accepting the sessions of another webapp */
155+
if (fstat(data->fd, &sbuf) || (sbuf.st_uid != 0 && sbuf.st_uid != getuid() && sbuf.st_uid != geteuid())) {
156156
close(data->fd);
157157
data->fd = -1;
158158
return;
159-
}
159+
}
160160
#endif
161161
flock(data->fd, LOCK_EX);
162162

0 commit comments

Comments
 (0)