]> granicus.if.org Git - php/commitdiff
ext/sodium: Fix sodium_pad() with blocksize >= 256
authorFrank Denis <github@pureftpd.org>
Sun, 14 Oct 2018 08:37:37 +0000 (10:37 +0200)
committerFrank Denis <github@pureftpd.org>
Sun, 14 Oct 2018 08:37:37 +0000 (10:37 +0200)
Backport from PECL libsodium-php 2.0.12

ext/sodium/libsodium.c

index a5f892fb7a371f5a63710b2b563030fd6559efe1..5462700f6c4daba178696169b51e61731c39b8ae 100644 (file)
@@ -3424,7 +3424,8 @@ PHP_FUNCTION(sodium_pad)
                tail = &ZSTR_VAL(padded)[xpadded_len];
                mask = 0U;
                for (i = 0; i < blocksize; i++) {
-                       barrier_mask = (unsigned char) (((i ^ xpadlen) - 1U) >> 8);
+                       barrier_mask = (unsigned char)
+                               (((i ^ xpadlen) - 1U) >> ((sizeof(size_t) - 1U) * CHAR_BIT));
                        tail[-i] = (tail[-i] & mask) | (0x80 & barrier_mask);
                        mask |= barrier_mask;
                }