Skip to content

Commit e79fb0e

Browse files
committed
W32 build fix attempt
1 parent b7abc48 commit e79fb0e

File tree

5 files changed

+13
-21
lines changed

5 files changed

+13
-21
lines changed

ext/hash/hash.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,6 @@ PHP_FUNCTION(hash_pbkdf2)
11101110
PHP_FUNCTION(hash_equals)
11111111
{
11121112
zval *known_zval, *user_zval;
1113-
char *known_str, *user_str;
11141113
int result = 0;
11151114

11161115
if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz", &known_zval, &user_zval) == FAILURE) {
@@ -1128,15 +1127,8 @@ PHP_FUNCTION(hash_equals)
11281127
RETURN_THROWS();
11291128
}
11301129

1131-
if (Z_STRLEN_P(known_zval) != Z_STRLEN_P(user_zval)) {
1132-
RETURN_FALSE;
1133-
}
1134-
1135-
known_str = Z_STRVAL_P(known_zval);
1136-
user_str = Z_STRVAL_P(user_zval);
1137-
11381130
/* This is security sensitive code. Do not optimize this for speed. */
1139-
result = php_safe_bcmp(known_str, user_str, Z_STRLEN_P(known_zval));
1131+
result = php_safe_bcmp(Z_STR_P(known_zval), Z_STR_P(user_zval));
11401132

11411133
RETURN_BOOL(0 == result);
11421134
}

ext/standard/password.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,14 @@ static bool php_password_bcrypt_needs_rehash(const zend_string *hash, zend_array
152152
}
153153

154154
static bool php_password_bcrypt_verify(const zend_string *password, const zend_string *hash) {
155-
size_t i;
156155
int status = 0;
157156
zend_string *ret = php_crypt(ZSTR_VAL(password), (int)ZSTR_LEN(password), ZSTR_VAL(hash), (int)ZSTR_LEN(hash), 1);
158157

159158
if (!ret) {
160159
return 0;
161160
}
162161

163-
if (ZSTR_LEN(ret) != ZSTR_LEN(hash) || ZSTR_LEN(hash) < 13) {
162+
if (ZSTR_LEN(hash) < 13) {
164163
zend_string_free(ret);
165164
return 0;
166165
}
@@ -169,7 +168,7 @@ static bool php_password_bcrypt_verify(const zend_string *password, const zend_s
169168
* resistance towards timing attacks. This is a constant time
170169
* equality check that will always check every byte of both
171170
* values. */
172-
status = php_safe_bcmp(ZSTR_VAL(ret), ZSTR_VAL(hash), ZSTR_LEN(hash));
171+
status = php_safe_bcmp(ret, hash);
173172

174173
zend_string_free(ret);
175174
return status == 0;

main/php.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ END_EXTERN_C()
180180
#endif
181181

182182
BEGIN_EXTERN_C()
183-
PHPAPI int php_safe_bcmp(const void *a, const void *b, size_t siz);
183+
PHPAPI int php_safe_bcmp(const zend_string *a, const zend_string *b);
184184
END_EXTERN_C()
185185

186186
#ifndef HAVE_STRTOK_R

main/safe_bcmp.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
/*
2-
+----------------------------------------------------------------------+
3-
| PHP Version 8 |
42
+----------------------------------------------------------------------+
53
| Copyright (c) The PHP Group |
64
+----------------------------------------------------------------------+
@@ -12,22 +10,25 @@
1210
| obtain it through the world-wide-web, please send a note to |
1311
| [email protected] so we can mail you a copy immediately. |
1412
+----------------------------------------------------------------------+
15-
| Author: |
13+
| Author: David Carlier <[email protected]> |
1614
+----------------------------------------------------------------------+
1715
*/
1816

1917
#include "php.h"
2018

2119
#include <string.h>
2220

23-
PHPAPI int php_safe_bcmp(const void *a, const void *b, size_t siz)
21+
PHPAPI int php_safe_bcmp(const zend_string *a, const zend_string *b)
2422
{
25-
const volatile unsigned char *ua = (const volatile unsigned char *)a;
26-
const volatile unsigned char *ub = (const volatile unsigned char *)b;
23+
const volatile unsigned char *ua = (const volatile unsigned char *)ZSTR_VAL(a);
24+
const volatile unsigned char *ub = (const volatile unsigned char *)ZSTR_VAL(b);
2725
size_t i = 0;
2826
int r = 0;
2927

30-
while (i < siz) {
28+
if (ZSTR_LEN(a) != ZSTR_LEN(b))
29+
return -1;
30+
31+
while (i < ZSTR_LEN(a)) {
3132
r |= ua[i] ^ ub[i];
3233
++i;
3334
}

win32/build/config.w32

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ ADD_SOURCES("main", "main.c snprintf.c spprintf.c getopt.c fopen_wrappers.c \
265265
php_scandir.c php_ini.c SAPI.c rfc1867.c php_content_types.c strlcpy.c \
266266
strlcat.c reentrancy.c php_variables.c php_ticks.c network.c \
267267
php_open_temporary_file.c output.c internal_functions.c \
268-
php_syslog.c php_odbc_utils.c");
268+
php_syslog.c php_odbc_utils.c safe_bcmp.c");
269269
ADD_FLAG("CFLAGS_BD_MAIN", "/D ZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
270270
if (VS_TOOLSET && VCVERS >= 1914) {
271271
ADD_FLAG("CFLAGS_BD_MAIN", "/d2FuncCache1");

0 commit comments

Comments
 (0)