Skip to content

Commit a76882b

Browse files
committed
W32 build fix attempt
1 parent 737d65f commit a76882b

File tree

5 files changed

+19
-21
lines changed

5 files changed

+19
-21
lines changed

ext/hash/hash.c

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

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

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

11421134
RETURN_BOOL(0 == result);
11431135
}

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: 14 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,31 @@
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+
/*
22+
* Returns 0 if both inputs match, 1 if they don't.
23+
* Returns -1 early if inputs do not have the same lengths.
24+
*
25+
*/
26+
PHPAPI int php_safe_bcmp(const zend_string *a, const zend_string *b)
2427
{
25-
const volatile unsigned char *ua = (const volatile unsigned char *)a;
26-
const volatile unsigned char *ub = (const volatile unsigned char *)b;
28+
const volatile unsigned char *ua = (const volatile unsigned char *)ZSTR_VAL(a);
29+
const volatile unsigned char *ub = (const volatile unsigned char *)ZSTR_VAL(b);
2730
size_t i = 0;
2831
int r = 0;
2932

30-
while (i < siz) {
33+
if (ZSTR_LEN(a) != ZSTR_LEN(b)) {
34+
return -1;
35+
}
36+
37+
while (i < ZSTR_LEN(a)) {
3138
r |= ua[i] ^ ub[i];
3239
++i;
3340
}

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)