]> git.feebdaed.xyz Git - 0xmirror/radare2.git/commitdiff
Fix asan uaf in print_regcolor
authorpancake <pancake@nopcode.org>
Fri, 19 Dec 2025 22:38:17 +0000 (23:38 +0100)
committerpancake <pancake@nopcode.org>
Fri, 19 Dec 2025 22:38:36 +0000 (23:38 +0100)
libr/util/print_regcolor.c
test/unit/test_ovf.c

index dca70fa58a2884a244ca248b62c6b3f0315eb6bd..aa3f3bf447cd265ea63b9e113cc32227d99a5c98 100644 (file)
@@ -40,8 +40,8 @@ static bool token_name (const char *p, char *name, size_t name_sz) {
 }
 
 static int reg_item_cmp (const RRegItem *a, const RRegItem *b) {
-       const int offa = (a->offset << 4) + a->size;
-       const int offb = (b->offset << 4) + b->size;
+       const int offa = ((unsigned)a->offset << 4) + a->size;
+       const int offb = ((unsigned)b->offset << 4) + b->size;
        if (offa != offb) {
                return (offa > offb) - (offa < offb);
        }
index 6d04412f743e590cd24350a42ef50f9accf1d141..0b5d285b60f84975ab9e1420547acdee420649d6 100644 (file)
@@ -14,9 +14,9 @@ int test_overflow_add(void) {
        mu_assert_true (ST16_ADD_OVFCHK (ST16_MIN, (st16)-1), "st16-add (min, -1)");
        mu_assert_true (UT16_ADD_OVFCHK (10, (ut16)-20), "ut16-add (10, -20)");
        mu_assert_false (ST16_ADD_OVFCHK ((st16)-10, 20), "st16-add (-10, 20)");
-       mu_assert_true (ST32_ADD_OVFCHK (ST32_MIN, (st32)-20), "st32-add (min, -20)");
+       mu_assert_true (ST32_ADD_OVFCHK (ST32_MIN, -20), "st32-add (min, -20)");
        mu_assert_false (ST32_ADD_OVFCHK ((st32)-10, 20), "st32-add (-10, 20)");
-       mu_assert_true (ST64_ADD_OVFCHK (ST64_MIN, (st64)-20), "st64-add (min, -20)");
+       mu_assert_true (ST64_ADD_OVFCHK (ST64_MIN, -20), "st64-add (min, -20)");
        mu_assert_false (ST64_ADD_OVFCHK ((st64)-10, 20), "st64-add 3");
        mu_end;
 }