Skip to content

Commit b356986

Browse files
committed
Fix the crypt sha apis build (with recent clang versions).
Removing the said subtraction by casting instead. While at it fixing werror level on phpdbg too. Closes #8897.
1 parent d66d477 commit b356986

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ PHP NEWS
1717
. Fixed bug GH-8847 (PHP hanging infinitly at 100% cpu when check php
1818
syntaxe of a valid file). (Dmitry)
1919

20+
- Standard:
21+
. Fixed the crypt_sha256/512 api build with clang > 12. (David Carier)
22+
2023
07 Jul 2022, PHP 8.0.21
2124

2225
- Core:

ext/standard/crypt_sha256.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -371,15 +371,15 @@ char * php_sha256_crypt_r(const char *key, const char *salt, char *buffer, int b
371371
salt_len = MIN(strcspn(salt, "$"), SALT_LEN_MAX);
372372
key_len = strlen(key);
373373

374-
if ((key - (char *) 0) % __alignof__ (uint32_t) != 0) {
374+
if ((uintptr_t)key % __alignof__ (uint32_t) != 0) {
375375
char *tmp = (char *) alloca(key_len + __alignof__(uint32_t));
376-
key = copied_key = memcpy(tmp + __alignof__(uint32_t) - (tmp - (char *) 0) % __alignof__(uint32_t), key, key_len);
376+
key = copied_key = memcpy(tmp + __alignof__(uint32_t) - (uintptr_t)tmp % __alignof__(uint32_t), key, key_len);
377377
}
378378

379-
if ((salt - (char *) 0) % __alignof__(uint32_t) != 0) {
379+
if ((uintptr_t)salt % __alignof__(uint32_t) != 0) {
380380
char *tmp = (char *) alloca(salt_len + 1 + __alignof__(uint32_t));
381381
salt = copied_salt =
382-
memcpy(tmp + __alignof__(uint32_t) - (tmp - (char *) 0) % __alignof__ (uint32_t), salt, salt_len);
382+
memcpy(tmp + __alignof__(uint32_t) - (uintptr_t)tmp % __alignof__ (uint32_t), salt, salt_len);
383383
copied_salt[salt_len] = 0;
384384
}
385385

ext/standard/crypt_sha512.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -405,15 +405,15 @@ php_sha512_crypt_r(const char *key, const char *salt, char *buffer, int buflen)
405405
salt_len = MIN(strcspn(salt, "$"), SALT_LEN_MAX);
406406
key_len = strlen(key);
407407

408-
if ((key - (char *) 0) % __alignof__ (uint64_t) != 0) {
408+
if ((uintptr_t)key % __alignof__ (uint64_t) != 0) {
409409
char *tmp = (char *) alloca (key_len + __alignof__ (uint64_t));
410410
key = copied_key =
411-
memcpy(tmp + __alignof__(uint64_t) - (tmp - (char *) 0) % __alignof__(uint64_t), key, key_len);
411+
memcpy(tmp + __alignof__(uint64_t) - (uintptr_t)tmp % __alignof__(uint64_t), key, key_len);
412412
}
413413

414-
if ((salt - (char *) 0) % __alignof__ (uint64_t) != 0) {
414+
if ((uintptr_t)salt % __alignof__ (uint64_t) != 0) {
415415
char *tmp = (char *) alloca(salt_len + 1 + __alignof__(uint64_t));
416-
salt = copied_salt = memcpy(tmp + __alignof__(uint64_t) - (tmp - (char *) 0) % __alignof__(uint64_t), salt, salt_len);
416+
salt = copied_salt = memcpy(tmp + __alignof__(uint64_t) - (uintptr_t)tmp % __alignof__(uint64_t), salt, salt_len);
417417
copied_salt[salt_len] = 0;
418418
}
419419

sapi/phpdbg/phpdbg.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ static ssize_t phpdbg_stdiop_write(php_stream *stream, const char *buf, size_t c
910910
while (data->fd >= 0) {
911911
struct stat stat[3];
912912
memset(stat, 0, sizeof(stat));
913-
if (((fstat(fileno(stderr), &stat[2]) < 0) & (fstat(fileno(stdout), &stat[0]) < 0)) | (fstat(data->fd, &stat[1]) < 0)) {
913+
if (((fstat(fileno(stderr), &stat[2]) < 0) && (fstat(fileno(stdout), &stat[0]) < 0)) || (fstat(data->fd, &stat[1]) < 0)) {
914914
break;
915915
}
916916

0 commit comments

Comments
 (0)