]> git.feebdaed.xyz Git - 0xmirror/radare2.git/commitdiff
Add and fix more memory leaking tests
authorpancake <pancake@nowsecure.com>
Sat, 20 Dec 2025 12:04:02 +0000 (13:04 +0100)
committerGitHub <noreply@github.com>
Sat, 20 Dec 2025 12:04:02 +0000 (13:04 +0100)
.github/workflows/tcc.yml
binr/r2r/run.c
libr/anal/p/anal_tp.c
libr/arch/p/x86/plugin_cs.c
libr/bin/format/mach0/mach0.c
libr/core/canal.c
test/db/leak/open

index 943fd2c96e19089e175d267fb2e3dd595699ffc0..5ec03a7e4e8fdde166792205b629baae4205124e 100644 (file)
@@ -36,7 +36,7 @@ jobs:
     - name: Install dependencies
       run: |
         sudo apt update --assume-yes
-        sudo apt-get --assume-yes install gperf wheel setuptools || true
+        sudo apt-get --assume-yes install gperf || true
         sudo pip install r2pipe --break-system-packages
     - name: Configure, build and install (Using the new ABI)
       env:
@@ -79,7 +79,7 @@ jobs:
     - name: Install dependencies
       run: |
         sudo apt update --assume-yes
-        sudo apt-get --assume-yes install gperf wheel setuptools || true
+        sudo apt-get --assume-yes install gperf || true
         sudo pip install r2pipe --break-system-packages
     - name: Configure, build and install
       env:
@@ -107,7 +107,7 @@ jobs:
           cd tinycc && git checkout mob
           git reset --hard 560526a49dfffef118bcb7fba83c727639ec0a1d
           sudo apt update --assume-yes
-          sudo apt-get --assume-yes install gperf wheel setuptools || true
+          sudo apt-get --assume-yes install gperf || true
           sudo pip install r2pipe --break-system-packages
     - name: Compiling and installing TinyCC
       working-directory: tinycc
@@ -189,7 +189,7 @@ jobs:
           cd tinycc && git checkout mob
           git reset --hard 560526a49dfffef118bcb7fba83c727639ec0a1d
           sudo apt-get update --assume-yes
-          sudo apt-get --assume-yes install gperf wheel setuptools || true
+          sudo apt-get --assume-yes install gperf || true
           sudo pip install r2pipe --break-system-packages
     - name: Compiling and installing TinyCC
       working-directory: tinycc
@@ -253,7 +253,7 @@ jobs:
     - name: Install dependencies
       run: |
         sudo apt update --assume-yes
-        sudo apt-get --assume-yes install gperf wheel setuptools valgrind || true
+        sudo apt-get --assume-yes install gperf valgrind
         sudo pip install r2pipe --break-system-packages
     - name: Configure, build and install
       env:
@@ -266,6 +266,7 @@ jobs:
       env:
         PKG_CONFIG_PATH: /usr/lib/x86_64-linux-gnu/pkgconfig
       run: |
+        valgrind --version
         r2 -v
         r2r -v
         r2r test/db/leak
index f5933a4a7932b7653a5b9471c5078ea7aa499a13..f622cfe6e92481f747f2338f55ca280923f23373 100644 (file)
@@ -1463,6 +1463,7 @@ static bool parse_valgrind_leak_summary(const char *valgrind_out) {
        return definitely_lost == 0 && indirectly_lost == 0 && possibly_lost == 0;
 }
 
+#if __linux__
 // Run r2 test wrapped with valgrind
 // Similar to run_r2_test but wraps the command with valgrind
 static R2RProcessOutput *run_r2_test_with_valgrind(R2RRunConfig *config, ut64 timeout_ms, int repeat, const char *cmds, RList *files, RList *extra_args, RList *extra_env, bool load_plugins, R2RCmdRunner runner, void *user) {
@@ -1545,19 +1546,13 @@ static R2RProcessOutput *run_r2_test_with_valgrind(R2RRunConfig *config, ut64 ti
        r_list_free (envvals);
        return out;
 }
+#endif
 
 // Run a leak test with valgrind
 // Returns process output with valgrind output in stdout/stderr
 R_API R2RProcessOutput *r2r_run_leak_test(R2RRunConfig *config, R2RCmdTest *test, R2RCmdRunner runner, void *user) {
-// Check if we're on Linux
-#if !R2__UNIX__
-       R2RProcessOutput *out = R_NEW0 (R2RProcessOutput);
-       out->ret = 1;
-       out->out = strdup ("Leak tests only run on Linux");
-       out->err = strdup ("");
-       return out;
-#else
-       // Check if valgrind is available
+#if __linux__
+       // Check if valgrind is available and we run only this stuff in linux
        char *valgrind_bin = r_file_path ("valgrind");
        if (!valgrind_bin) {
                R2RProcessOutput *out = R_NEW0 (R2RProcessOutput);
@@ -1610,6 +1605,12 @@ R_API R2RProcessOutput *r2r_run_leak_test(R2RRunConfig *config, R2RCmdTest *test
        r_list_free (files);
        r_list_free (extra_env);
        return out;
+#else
+       R2RProcessOutput *out = R_NEW0 (R2RProcessOutput);
+       out->ret = 1;
+       out->out = strdup ("Leak tests only run on Linux");
+       out->err = strdup ("");
+       return out;
 #endif
 }
 
index 988a270df2369d038f527402338119724c4b5a39..9826d99ad386ab1c74d1c7eb8ea1d2b119afcf62 100644 (file)
@@ -1488,6 +1488,7 @@ repeat:
                                int ret2 = r_anal_op (anal, next_op, addr + ret, buf_ptr + i + ret, left, op_tions);
                                if (ret2 < 1) {
                                        r_anal_op_fini (&aop);
+                                       r_anal_op_fini (next_op);
                                        break;
                                }
                                have_cached_op = true;
index f6583fd2ef15abf22d40d53fbef5b54fd1754958..0427d033a9f2c78c656de7654534825245b3a4ae 100644 (file)
@@ -986,39 +986,17 @@ static void anop_esil(RArchSession *as, RAnalOp *op, ut64 addr, const ut8 *buf,
        case X86_INS_SAR:
                // TODO: Set CF. See case X86_INS_SHL for more details.
                {
-#if 0
-                       ut64 val = 0;
-                       switch (gop.insn->detail->x86.operands[0].size) {
-                       case 1:
-                               val = 0x80;
-                               break;
-                       case 2:
-                               val = 0x8000;
-                               break;
-                       case 4:
-                               val = 0x80000000;
-                               break;
-                       case 8:
-                               val = 0x8000000000000000;
-                               break;
-                       default:
-                               val = 0x80;
-                       }
-                       src = getarg (&gop, 1, 0, NULL);
-                       dst = getarg (&gop, 0, 0, NULL);
-                       esilprintf (op, "%s,1,%s,>>,0x%"PFMT64x",%s,&,|,%s,=,1,%s,&,cf,=,1,REPEAT", src, dst, val, dst, dst, dst);
-#endif
-                       ut32 bitsize;
-                       src = getarg (&gop, 1, 0, NULL, NULL);
-                       dst_r = getarg (&gop, 0, 0, NULL, NULL);
-                       dst_w = getarg (&gop, 0, 1, NULL, &bitsize);
-                       esilprintf (op, "0,cf,:=,1,%s,-,1,<<,%s,&,?{,1,cf,:=,},%s,%s,ASR,%s,$z,zf,:=,$p,pf,:=,%d,$s,sf,:=",
-                               src, dst_r, src, dst_r, dst_w, bitsize - 1);
-                       free (src);
-                       free (dst_r);
-                       free (dst_w);
-               }
-               break;
+               ut32 bitsize;
+               src = getarg (&gop, 1, 0, NULL, NULL);
+               dst_r = getarg (&gop, 0, 0, NULL, NULL);
+               dst_w = getarg (&gop, 0, 1, NULL, &bitsize);
+               esilprintf (op, "0,cf,:=,1,%s,-,1,<<,%s,&,?{,1,cf,:=,},%s,%s,ASR,%s,$z,zf,:=,$p,pf,:=,%d,$s,sf,:=",
+                       src, dst_r, src, dst_r, dst_w, bitsize - 1);
+               free (src);
+               free (dst_r);
+               free (dst_w);
+       }
+       break;
        case X86_INS_SARX:
                {
                        dst = getarg (&gop, 0, 1, NULL, NULL);
index ac0007979454c1234c52611e1899d96fd820f67c..aa0104321f783d829d5e91dda9072c31923315b7 100644 (file)
@@ -70,6 +70,7 @@ typedef struct {
 
 static void import_hash_free(HtPPKv *kv) {
        if (kv) {
+               free (kv->key);
                r_bin_import_free (kv->value);
        }
 }
index 617ce57f4fdba4b12537b876cadf993e3cc338f2..ddea96e892fed4d71fa7b6ac9862583624777d16 100644 (file)
@@ -218,12 +218,17 @@ static char *is_string_at(RCore *core, ut64 addr, int *olen) {
        if (len < 1) {
                ret = 0;
                free (str);
-               len = -1;
-       } else if (olen) {
+               return NULL;
+       }
+       if (olen) {
                *olen = len;
        }
        // NOTE: coverity says that ret is always 0 here, so str is dead code
-       return ret? (char *)str: NULL;
+       if (ret && len > 0) {
+               return (char *)str;
+       }
+       free (str);
+       return NULL;
 }
 
 /* returns the R_ANAL_ADDR_TYPE_* of the address 'addr' */
index 7c17e37126cdc071af18a3beab8d4a80bdda4040..81e1c2d414d5e00390b1ce3f0032837bd31a28cb 100644 (file)
@@ -18,3 +18,35 @@ hello
 EOF
 RUN
 
+NAME=leak opening macho
+FILE=bins/mach0/hello-osx-i386
+CMDS=<<EOF
+?e hello
+EOF
+EXPECT=<<EOF
+hello
+EOF
+RUN
+
+NAME=leak analysis elf
+FILE=bins/elf/ip-riscv
+ARGS=-AA
+CMDS=<<EOF
+?e hello
+EOF
+EXPECT=<<EOF
+hello
+EOF
+RUN
+
+NAME=leak analysis macho
+FILE=bins/mach0/hello-osx-i386
+BROKEN=1
+ARGS=-AA
+CMDS=<<EOF
+?e hello
+EOF
+EXPECT=<<EOF
+hello
+EOF
+RUN