com php-src: ext/sodium: sodium_pad(): do not cop y any bytes if the string is empty: ext/sodiu m/libsodium.c
| From: | Frank Denis | Date: | Sun, 14 Oct 2018 08:43:21 +0000 |
| Subject: | com php-src: ext/sodium: sodium_pad(): do not cop y any bytes if the string is empty: ext/sodiu m/libsodium.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-103458@lists.php.net to get a copy of this message | ||
Commit: 82a93c17943c510b0bf33904429d47fbb74d9fc2
Author: Frank Denis <github@pureftpd.org> Sun, 14 Oct 2018 10:43:21 +0200
Parents: bf48d0c475c0c1312fbf763d221d94e87cf480d0
Branches: PHP-7.2
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=82a93c17943c510b0bf33904429d47fbb74d9fc2
Log:
ext/sodium: sodium_pad(): do not copy any bytes if the string is empty
Spotted by San Zhang, thanks!
Backport from PECL libsodium-php 2.0.13
Changed paths:
M ext/sodium/libsodium.c
Diff:
diff --git a/ext/sodium/libsodium.c b/ext/sodium/libsodium.c
index 5462700..b6a4925 100644
--- a/ext/sodium/libsodium.c
+++ b/ext/sodium/libsodium.c
@@ -3402,12 +3402,17 @@ PHP_FUNCTION(sodium_pad)
st = 1U;
i = 0U;
k = unpadded_len;
- for (j = 0U; j <= xpadded_len; j++) {
- ZSTR_VAL(padded)[j] = unpadded[i];
- k -= st;
- st = (size_t) (~(((( (((uint64_t) k) >> 48) | (((uint64_t) k) >> 32) |
- (k >> 16) | k) & 0xffff) - 1U) >> 16)) & 1U;
- i += st;
+ if (unpadded_len > 0) {
+ st = 1U;
+ i = 0U;
+ k = unpadded_len;
+ for (j = 0U; j <= xpadded_len; j++) {
+ ZSTR_VAL(padded)[j] = unpadded[i];
+ k -= st;
+ st = (size_t) (~(((( (((uint64_t) k) >> 48) | (((uint64_t) k) >> 32) |
+ (k >> 16) | k) & 0xffff) - 1U) >> 16)) & 1U;
+ i += st;
+ }
}
#if SODIUM_LIBRARY_VERSION_MAJOR > 9 || (SODIUM_LIBRARY_VERSION_MAJOR == 9 &&
SODIUM_LIBRARY_VERSION_MINOR >= 6)
if (sodium_pad(NULL, (unsigned char *) ZSTR_VAL(padded), unpadded_len,