summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrank Denis <github@pureftpd.org>2018-10-14 10:43:21 +0200
committerFrank Denis <github@pureftpd.org>2018-10-14 10:43:21 +0200
commit82a93c17943c510b0bf33904429d47fbb74d9fc2 (patch)
tree04984ae2a1e55a3f814e3005a16db259956c41a6
parentbf48d0c475c0c1312fbf763d221d94e87cf480d0 (diff)
downloadphp-git-82a93c17943c510b0bf33904429d47fbb74d9fc2.tar.gz
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
-rw-r--r--ext/sodium/libsodium.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/ext/sodium/libsodium.c b/ext/sodium/libsodium.c
index 5462700f6c..b6a4925498 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,