Skip to content

Commit a4fa962

Browse files
committed
Use different alloca flags for crypt_sha
1 parent 1af023e commit a4fa962

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

ext/standard/crypt_sha256.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -369,17 +369,18 @@ char * php_sha256_crypt_r(const char *key, const char *salt, char *buffer, int b
369369

370370
salt_len = MIN(strcspn(salt, "$"), SALT_LEN_MAX);
371371
key_len = strlen(key);
372-
ALLOCA_FLAG(use_heap);
373372
char *tmp_key = NULL;
373+
ALLOCA_FLAG(use_heap_key);
374374
char *tmp_salt = NULL;
375+
ALLOCA_FLAG(use_heap_salt);
375376

376377
if ((key - (char *) 0) % __alignof__ (uint32_t) != 0) {
377-
tmp_key = (char *) do_alloca(key_len + __alignof__(uint32_t), use_heap);
378+
tmp_key = (char *) do_alloca(key_len + __alignof__(uint32_t), use_heap_key);
378379
key = copied_key = memcpy(tmp_key + __alignof__(uint32_t) - (tmp_key - (char *) 0) % __alignof__(uint32_t), key, key_len);
379380
}
380381

381382
if ((salt - (char *) 0) % __alignof__(uint32_t) != 0) {
382-
tmp_salt = (char *) do_alloca(salt_len + 1 + __alignof__(uint32_t), use_heap);
383+
tmp_salt = (char *) do_alloca(salt_len + 1 + __alignof__(uint32_t), use_heap_salt);
383384
salt = copied_salt =
384385
memcpy(tmp_salt + __alignof__(uint32_t) - (tmp_salt - (char *) 0) % __alignof__ (uint32_t), salt, salt_len);
385386
copied_salt[salt_len] = 0;
@@ -445,7 +446,7 @@ char * php_sha256_crypt_r(const char *key, const char *salt, char *buffer, int b
445446
sha256_finish_ctx(&alt_ctx, temp_result);
446447

447448
/* Create byte sequence P. */
448-
cp = p_bytes = do_alloca(key_len, use_heap);
449+
cp = p_bytes = do_alloca(key_len, use_heap_key);
449450
for (cnt = key_len; cnt >= 32; cnt -= 32) {
450451
cp = __php_mempcpy((void *)cp, (const void *)temp_result, 32);
451452
}
@@ -463,7 +464,7 @@ char * php_sha256_crypt_r(const char *key, const char *salt, char *buffer, int b
463464
sha256_finish_ctx(&alt_ctx, temp_result);
464465

465466
/* Create byte sequence S. */
466-
cp = s_bytes = do_alloca(salt_len, use_heap);
467+
cp = s_bytes = do_alloca(salt_len, use_heap_salt);
467468
for (cnt = salt_len; cnt >= 32; cnt -= 32) {
468469
cp = __php_mempcpy(cp, temp_result, 32);
469470
}
@@ -574,13 +575,13 @@ char * php_sha256_crypt_r(const char *key, const char *salt, char *buffer, int b
574575
ZEND_SECURE_ZERO(copied_salt, salt_len);
575576
}
576577
if (tmp_key != NULL) {
577-
free_alloca(tmp_key, use_heap);
578+
free_alloca(tmp_key, use_heap_key);
578579
}
579580
if (tmp_salt != NULL) {
580-
free_alloca(tmp_salt, use_heap);
581+
free_alloca(tmp_salt, use_heap_salt);
581582
}
582-
free_alloca(p_bytes, use_heap);
583-
free_alloca(s_bytes, use_heap);
583+
free_alloca(p_bytes, use_heap_key);
584+
free_alloca(s_bytes, use_heap_salt);
584585

585586
return buffer;
586587
}

ext/standard/crypt_sha512.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -403,18 +403,19 @@ php_sha512_crypt_r(const char *key, const char *salt, char *buffer, int buflen)
403403

404404
salt_len = MIN(strcspn(salt, "$"), SALT_LEN_MAX);
405405
key_len = strlen(key);
406-
ALLOCA_FLAG(use_heap);
407406
char *tmp_key = NULL;
407+
ALLOCA_FLAG(use_heap_key);
408408
char *tmp_salt = NULL;
409+
ALLOCA_FLAG(use_heap_salt);
409410

410411
if ((key - (char *) 0) % __alignof__ (uint64_t) != 0) {
411-
tmp_key = (char *) do_alloca(key_len + __alignof__ (uint64_t), use_heap);
412+
tmp_key = (char *) do_alloca(key_len + __alignof__ (uint64_t), use_heap_key);
412413
key = copied_key =
413414
memcpy(tmp_key + __alignof__(uint64_t) - (tmp_key - (char *) 0) % __alignof__(uint64_t), key, key_len);
414415
}
415416

416417
if ((salt - (char *) 0) % __alignof__ (uint64_t) != 0) {
417-
tmp_salt = (char *) do_alloca(salt_len + 1 + __alignof__(uint64_t), use_heap);
418+
tmp_salt = (char *) do_alloca(salt_len + 1 + __alignof__(uint64_t), use_heap_salt);
418419
salt = copied_salt = memcpy(tmp_salt + __alignof__(uint64_t) - (tmp_salt - (char *) 0) % __alignof__(uint64_t), salt, salt_len);
419420
copied_salt[salt_len] = 0;
420421
}
@@ -479,7 +480,7 @@ php_sha512_crypt_r(const char *key, const char *salt, char *buffer, int buflen)
479480
sha512_finish_ctx(&alt_ctx, temp_result);
480481

481482
/* Create byte sequence P. */
482-
cp = p_bytes = do_alloca(key_len, use_heap);
483+
cp = p_bytes = do_alloca(key_len, use_heap_key);
483484
for (cnt = key_len; cnt >= 64; cnt -= 64) {
484485
cp = __php_mempcpy((void *) cp, (const void *)temp_result, 64);
485486
}
@@ -498,7 +499,7 @@ php_sha512_crypt_r(const char *key, const char *salt, char *buffer, int buflen)
498499
sha512_finish_ctx(&alt_ctx, temp_result);
499500

500501
/* Create byte sequence S. */
501-
cp = s_bytes = do_alloca(salt_len, use_heap);
502+
cp = s_bytes = do_alloca(salt_len, use_heap_salt);
502503
for (cnt = salt_len; cnt >= 64; cnt -= 64) {
503504
cp = __php_mempcpy(cp, temp_result, 64);
504505
}
@@ -621,13 +622,13 @@ php_sha512_crypt_r(const char *key, const char *salt, char *buffer, int buflen)
621622
ZEND_SECURE_ZERO(copied_salt, salt_len);
622623
}
623624
if (tmp_key != NULL) {
624-
free_alloca(tmp_key, use_heap);
625+
free_alloca(tmp_key, use_heap_key);
625626
}
626627
if (tmp_salt != NULL) {
627-
free_alloca(tmp_salt, use_heap);
628+
free_alloca(tmp_salt, use_heap_salt);
628629
}
629-
free_alloca(p_bytes, use_heap);
630-
free_alloca(s_bytes, use_heap);
630+
free_alloca(p_bytes, use_heap_key);
631+
free_alloca(s_bytes, use_heap_salt);
631632

632633
return buffer;
633634
}

0 commit comments

Comments
 (0)