]> git.codecow.com Git - Monocypher.git/commitdiff
Fixed NULL += 0 undefined behaviour
authorLoup Vaillant <loup@loup-vaillant.fr>
Thu, 23 Mar 2023 11:02:57 +0000 (12:02 +0100)
committerLoup Vaillant <loup@loup-vaillant.fr>
Thu, 23 Mar 2023 11:02:57 +0000 (12:02 +0100)
src/monocypher.c

index 0257fb5e7c7dc018f3c24869868a920bb76f4961..7fdebb0a94e9fc31a4f4807acf0730a485ca72e4 100644 (file)
@@ -377,6 +377,11 @@ void crypto_poly1305_init(crypto_poly1305_ctx *ctx, const u8 key[32])
 void crypto_poly1305_update(crypto_poly1305_ctx *ctx,
                             const u8 *message, size_t message_size)
 {
+       // Avoid undefined NULL pointer increments with empty messages
+       if (message_size == 0) {
+               return;
+       }
+
        // Align ourselves with block boundaries
        size_t aligned = MIN(gap(ctx->c_idx, 16), message_size);
        FOR (i, 0, aligned) {