Skip to content

Commit 81f09e8

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: Fix GH-18173: ext/hash relies on implementation-defined malloc alignment
2 parents c74b258 + 6c1b05c commit 81f09e8

17 files changed

Lines changed: 89 additions & 34 deletions

ext/hash/hash.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ static void php_hash_do_hash(
386386
}
387387
php_stream_close(stream);
388388
if (n < 0) {
389-
efree(context);
389+
php_hash_free_context(ops, context);
390390
RETURN_FALSE;
391391
}
392392
} else {
@@ -395,7 +395,7 @@ static void php_hash_do_hash(
395395

396396
digest = zend_string_alloc(ops->digest_size, 0);
397397
ops->hash_final((unsigned char *) ZSTR_VAL(digest), context);
398-
efree(context);
398+
php_hash_free_context(ops, context);
399399

400400
if (raw_output) {
401401
ZSTR_VAL(digest)[ops->digest_size] = 0;
@@ -534,7 +534,7 @@ static void php_hash_do_hash_hmac(
534534
}
535535
php_stream_close(stream);
536536
if (n < 0) {
537-
efree(context);
537+
php_hash_free_context(ops, context);
538538
efree(K);
539539
zend_string_efree(digest);
540540
RETURN_FALSE;
@@ -552,7 +552,7 @@ static void php_hash_do_hash_hmac(
552552
/* Zero the key */
553553
ZEND_SECURE_ZERO(K, ops->block_size);
554554
efree(K);
555-
efree(context);
555+
php_hash_free_context(ops, context);
556556

557557
if (raw_output) {
558558
ZSTR_VAL(digest)[ops->digest_size] = 0;
@@ -813,7 +813,7 @@ PHP_FUNCTION(hash_final)
813813
ZSTR_VAL(digest)[digest_len] = 0;
814814

815815
/* Invalidate the object from further use */
816-
efree(hash->context);
816+
php_hash_free_context(hash->ops, hash->context);
817817
hash->context = NULL;
818818

819819
if (raw_output) {
@@ -967,7 +967,7 @@ PHP_FUNCTION(hash_hkdf)
967967
ZEND_SECURE_ZERO(digest, ops->digest_size);
968968
ZEND_SECURE_ZERO(prk, ops->digest_size);
969969
efree(K);
970-
efree(context);
970+
php_hash_free_context(ops, context);
971971
efree(prk);
972972
efree(digest);
973973
ZSTR_VAL(returnval)[length] = 0;
@@ -1083,7 +1083,7 @@ PHP_FUNCTION(hash_pbkdf2)
10831083
efree(K1);
10841084
efree(K2);
10851085
efree(computed_salt);
1086-
efree(context);
1086+
php_hash_free_context(ops, context);
10871087
efree(digest);
10881088
efree(temp);
10891089

@@ -1348,7 +1348,7 @@ PHP_FUNCTION(mhash_keygen_s2k)
13481348
RETVAL_STRINGL(key, bytes);
13491349
ZEND_SECURE_ZERO(key, bytes);
13501350
efree(digest);
1351-
efree(context);
1351+
php_hash_free_context(ops, context);
13521352
efree(key);
13531353
}
13541354
}
@@ -1378,7 +1378,7 @@ static void php_hashcontext_dtor(zend_object *obj) {
13781378
php_hashcontext_object *hash = php_hashcontext_from_object(obj);
13791379

13801380
if (hash->context) {
1381-
efree(hash->context);
1381+
php_hash_free_context(hash->ops, hash->context);
13821382
hash->context = NULL;
13831383
}
13841384

@@ -1414,7 +1414,7 @@ static zend_object *php_hashcontext_clone(zend_object *zobj) {
14141414
newobj->ops->hash_init(newobj->context, NULL);
14151415

14161416
if (SUCCESS != newobj->ops->hash_copy(newobj->ops, oldobj->context, newobj->context)) {
1417-
efree(newobj->context);
1417+
php_hash_free_context(newobj->ops, newobj->context);
14181418
newobj->context = NULL;
14191419
return znew;
14201420
}

ext/hash/hash_adler32.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,6 @@ const php_hash_ops php_hash_adler32_ops = {
6868
4, /* what to say here? */
6969
4,
7070
sizeof(PHP_ADLER32_CTX),
71+
0,
7172
0
7273
};

ext/hash/hash_crc32.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ const php_hash_ops php_hash_crc32_ops = {
100100
4, /* what to say here? */
101101
4,
102102
sizeof(PHP_CRC32_CTX),
103+
0,
103104
0
104105
};
105106

@@ -115,6 +116,7 @@ const php_hash_ops php_hash_crc32b_ops = {
115116
4, /* what to say here? */
116117
4,
117118
sizeof(PHP_CRC32_CTX),
119+
0,
118120
0
119121
};
120122

@@ -130,5 +132,6 @@ const php_hash_ops php_hash_crc32c_ops = {
130132
4, /* what to say here? */
131133
4,
132134
sizeof(PHP_CRC32_CTX),
135+
0,
133136
0
134137
};

ext/hash/hash_fnv.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const php_hash_ops php_hash_fnv132_ops = {
3030
4,
3131
4,
3232
sizeof(PHP_FNV132_CTX),
33+
0,
3334
0
3435
};
3536

@@ -45,6 +46,7 @@ const php_hash_ops php_hash_fnv1a32_ops = {
4546
4,
4647
4,
4748
sizeof(PHP_FNV132_CTX),
49+
0,
4850
0
4951
};
5052

@@ -60,6 +62,7 @@ const php_hash_ops php_hash_fnv164_ops = {
6062
8,
6163
4,
6264
sizeof(PHP_FNV164_CTX),
65+
0,
6366
0
6467
};
6568

@@ -75,6 +78,7 @@ const php_hash_ops php_hash_fnv1a64_ops = {
7578
8,
7679
4,
7780
sizeof(PHP_FNV164_CTX),
81+
0,
7882
0
7983
};
8084

ext/hash/hash_gost.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,8 @@ const php_hash_ops php_hash_gost_ops = {
327327
32,
328328
32,
329329
sizeof(PHP_GOST_CTX),
330-
1
330+
1,
331+
0
331332
};
332333

333334
const php_hash_ops php_hash_gost_crypto_ops = {
@@ -342,5 +343,6 @@ const php_hash_ops php_hash_gost_crypto_ops = {
342343
32,
343344
32,
344345
sizeof(PHP_GOST_CTX),
345-
1
346+
1,
347+
0
346348
};

ext/hash/hash_haval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ const php_hash_ops php_hash_##p##haval##b##_ops = { \
250250
php_hash_serialize, \
251251
php_hash_unserialize, \
252252
PHP_HAVAL_SPEC, \
253-
((b) / 8), 128, sizeof(PHP_HAVAL_CTX), 1 }; \
253+
((b) / 8), 128, sizeof(PHP_HAVAL_CTX), 1, 0 }; \
254254
PHP_HASH_API void PHP_##p##HAVAL##b##Init(PHP_HAVAL_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args) \
255255
{ int i; context->count[0] = context->count[1] = 0; \
256256
for(i = 0; i < 8; i++) context->state[i] = D0[i]; \

ext/hash/hash_joaat.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const php_hash_ops php_hash_joaat_ops = {
3131
4,
3232
4,
3333
sizeof(PHP_JOAAT_CTX),
34+
0,
3435
0
3536
};
3637

ext/hash/hash_md.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ const php_hash_ops php_hash_md5_ops = {
2727
16,
2828
64,
2929
sizeof(PHP_MD5_CTX),
30-
1
30+
1,
31+
0
3132
};
3233

3334
const php_hash_ops php_hash_md4_ops = {
@@ -42,7 +43,8 @@ const php_hash_ops php_hash_md4_ops = {
4243
16,
4344
64,
4445
sizeof(PHP_MD4_CTX),
45-
1
46+
1,
47+
0
4648
};
4749

4850
static hash_spec_result php_md2_unserialize(php_hashcontext_object *hash, zend_long magic, const zval *zv);
@@ -59,7 +61,8 @@ const php_hash_ops php_hash_md2_ops = {
5961
16,
6062
16,
6163
sizeof(PHP_MD2_CTX),
62-
1
64+
1,
65+
0
6366
};
6467

6568
/* MD common stuff */

ext/hash/hash_murmur.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const php_hash_ops php_hash_murmur3a_ops = {
3131
4,
3232
4,
3333
sizeof(PHP_MURMUR3A_CTX),
34+
0,
3435
0
3536
};
3637

@@ -93,6 +94,7 @@ const php_hash_ops php_hash_murmur3c_ops = {
9394
16,
9495
4,
9596
sizeof(PHP_MURMUR3C_CTX),
97+
0,
9698
0
9799
};
98100

@@ -172,6 +174,7 @@ const php_hash_ops php_hash_murmur3f_ops = {
172174
16,
173175
8,
174176
sizeof(PHP_MURMUR3F_CTX),
177+
0,
175178
0
176179
};
177180

ext/hash/hash_ripemd.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ const php_hash_ops php_hash_ripemd128_ops = {
3131
16,
3232
64,
3333
sizeof(PHP_RIPEMD128_CTX),
34-
1
34+
1,
35+
0
3536
};
3637

3738
const php_hash_ops php_hash_ripemd160_ops = {
@@ -46,7 +47,8 @@ const php_hash_ops php_hash_ripemd160_ops = {
4647
20,
4748
64,
4849
sizeof(PHP_RIPEMD160_CTX),
49-
1
50+
1,
51+
0
5052
};
5153

5254
const php_hash_ops php_hash_ripemd256_ops = {
@@ -61,7 +63,8 @@ const php_hash_ops php_hash_ripemd256_ops = {
6163
32,
6264
64,
6365
sizeof(PHP_RIPEMD256_CTX),
64-
1
66+
1,
67+
0
6568
};
6669

6770
const php_hash_ops php_hash_ripemd320_ops = {
@@ -76,7 +79,8 @@ const php_hash_ops php_hash_ripemd320_ops = {
7679
40,
7780
64,
7881
sizeof(PHP_RIPEMD320_CTX),
79-
1
82+
1,
83+
0
8084
};
8185

8286
/* {{{ PHP_RIPEMD128Init

0 commit comments

Comments
 (0)