From fc31f75b9869218f8a5d94e4a92236cdea012d04 Mon Sep 17 00:00:00 2001 From: Fanda Vacek Date: Wed, 30 Oct 2024 23:36:01 +0100 Subject: [PATCH] Fix UB in function add_with_overflow_check_subopt() --- libshvchainpack/c/ccpon.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libshvchainpack/c/ccpon.c b/libshvchainpack/c/ccpon.c index 163c7375..d71099a4 100644 --- a/libshvchainpack/c/ccpon.c +++ b/libshvchainpack/c/ccpon.c @@ -803,11 +803,11 @@ const char* ccpon_unpack_skip_insignificant(ccpcp_unpack_context* unpack_context static bool add_with_overflow_check_subopt(int64_t a, int b, int64_t *result) { - int64_t res = a + b; - if (res < 0) { - return true; + // Check for overflow + if (a > INT64_MAX - b) { + return true; // Overflow occurred } - *result = res; + *result = a + b; return false; }