Skip to content

Commit 955eaee

Browse files
committed
W32 build fix attempt
1 parent 65dcb39 commit 955eaee

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
@@ -1107,7 +1107,6 @@ PHP_FUNCTION(hash_pbkdf2)
11071107
PHP_FUNCTION(hash_equals)
11081108
{
11091109
zval *known_zval, *user_zval;
1110-
char *known_str, *user_str;
11111110
int result = 0;
11121111

11131112
if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz", &known_zval, &user_zval) == FAILURE) {
@@ -1125,15 +1124,8 @@ PHP_FUNCTION(hash_equals)
11251124
RETURN_THROWS();
11261125
}
11271126

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

11381130
RETURN_BOOL(0 == result);
11391131
}

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
@@ -263,7 +263,7 @@ if (VS_TOOLSET && VCVERS >= 1914) {
263263
ADD_SOURCES("main", "main.c snprintf.c spprintf.c getopt.c fopen_wrappers.c \
264264
php_scandir.c php_ini.c SAPI.c rfc1867.c php_content_types.c strlcpy.c \
265265
strlcat.c reentrancy.c php_variables.c php_ticks.c network.c \
266-
php_open_temporary_file.c output.c internal_functions.c \
266+
php_open_temporary_file.c output.c internal_functions.c safe_bcmp.c \
267267
php_syslog.c");
268268
ADD_FLAG("CFLAGS_BD_MAIN", "/D ZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
269269
if (VS_TOOLSET && VCVERS >= 1914) {

0 commit comments

Comments
 (0)