com php-src: partial cleanup to work with size_t str leng th in password_hash: ext/standard/password.c
| From: | Anatol Belski | Date: | Fri, 14 Nov 2014 16:39:41 +0000 |
| Subject: | com php-src: partial cleanup to work with size_t str leng th in password_hash: ext/standard/password.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-83091@lists.php.net to get a copy of this message | ||
Commit: a85ce501da60999ded0f93d9889efa6792b2a6ec
Author: Anatol Belski <ab@php.net> Fri, 14 Nov 2014 11:27:23 +0100
Parents: dbddbcc950aec9956aaa942d1983981110984edd
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=a85ce501da60999ded0f93d9889efa6792b2a6ec
Log:
partial cleanup to work with size_t str length in password_hash
php_crypt() and co use int, though this is fair enough. Could
be refactored later for tidiness reasons.
Changed paths:
M ext/standard/password.c
Diff:
diff --git a/ext/standard/password.c b/ext/standard/password.c
index c58c28a..cd2170b 100644
--- a/ext/standard/password.c
+++ b/ext/standard/password.c
@@ -345,12 +345,11 @@ PHP_FUNCTION(password_hash)
if (options && (option_buffer = zend_symtable_str_find(options, "salt",
sizeof("salt")-1)) != NULL) {
char *buffer;
- size_t buffer_len_int = 0;
- size_t buffer_len;
+ size_t buffer_len = 0;
switch (Z_TYPE_P(option_buffer)) {
case IS_STRING:
buffer = estrndup(Z_STRVAL_P(option_buffer), Z_STRLEN_P(option_buffer));
- buffer_len_int = Z_STRLEN_P(option_buffer);
+ buffer_len = Z_STRLEN_P(option_buffer);
break;
case IS_LONG:
case IS_DOUBLE:
@@ -361,7 +360,7 @@ PHP_FUNCTION(password_hash)
convert_to_string(&cast_option_buffer);
if (Z_TYPE(cast_option_buffer) == IS_STRING) {
buffer = estrndup(Z_STRVAL(cast_option_buffer), Z_STRLEN(cast_option_buffer));
- buffer_len_int = Z_STRLEN(cast_option_buffer);
+ buffer_len = Z_STRLEN(cast_option_buffer);
zval_dtor(&cast_option_buffer);
break;
}
@@ -377,16 +376,18 @@ PHP_FUNCTION(password_hash)
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Non-string salt parameter supplied");
RETURN_NULL();
}
- if (buffer_len_int < 0) {
+
+ /* XXX all the crypt related APIs work with int for string length.
+ That should be revised for size_t and then we maybe don't require
+ the > INT_MAX check. */
+ if (buffer_len > INT_MAX) {
efree(hash_format);
efree(buffer);
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Supplied salt is too long");
- }
- buffer_len = (size_t) buffer_len_int;
- if (buffer_len < required_salt_len) {
+ } else if (buffer_len < required_salt_len) {
efree(hash_format);
efree(buffer);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Provided salt is too short: %lu expecting
%lu", (unsigned long) buffer_len, (unsigned long) required_salt_len);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Provided salt is too short: %zd expecting
%zd", buffer_len, required_salt_len);
RETURN_NULL();
} else if (php_password_salt_is_alphabet(buffer, buffer_len) == FAILURE) {
salt = safe_emalloc(required_salt_len, 1, 1);
@@ -394,7 +395,7 @@ PHP_FUNCTION(password_hash)
efree(hash_format);
efree(buffer);
efree(salt);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Provided salt is too short: %lu",
(unsigned long) buffer_len);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Provided salt is too short: %zd",
buffer_len);
RETURN_NULL();
}
salt_len = required_salt_len;