Skip to content

Commit

Permalink
Fix unit tc and leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
giridharprasath committed Jun 1, 2024
1 parent ec1f4f1 commit bb2ca7e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
6 changes: 3 additions & 3 deletions librz/core/cmd/cmd_search.c
Original file line number Diff line number Diff line change
Expand Up @@ -1373,7 +1373,6 @@ static void print_rop(RzCore *core, RzList /*<RzCoreAsmHit *>*/ *hitlist, RzCmdS
case RZ_OUTPUT_MODE_JSON:
pj_end(state->d.pj);
if (db && hit) {
rz_cons_printf("Gadget size: %d\n", (int)size);
const char *key = rz_strf(tmpbuf, "0x%08" PFMT64x, addr);
rop_classify(core, db, ropList, key, size);
}
Expand Down Expand Up @@ -1425,7 +1424,7 @@ static int rz_core_search_rop(RzCore *core, const char *greparg, int regexp, RzC
int delta = 0;
ut8 *buf;
RzIOMap *map;
RzAsmOp asmop;
RzAsmOp *asmop = rz_asm_op_new();

const ut64 search_from = rz_config_get_i(core->config, "search.from"),
search_to = rz_config_get_i(core->config, "search.to");
Expand Down Expand Up @@ -1611,7 +1610,7 @@ static int rz_core_search_rop(RzCore *core, const char *greparg, int regexp, RzC
RZ_MIN((delta - i), 4096));
end = i + 2048;
}
ret = rz_asm_disassemble(core->rasm, &asmop, buf + i, delta - i);
ret = rz_asm_disassemble(core->rasm, asmop, buf + i, delta - i);
if (ret) {
rz_asm_set_pc(core->rasm, from + i);
RzList *hitlist = construct_rop_gadget(core,
Expand Down Expand Up @@ -1682,6 +1681,7 @@ static int rz_core_search_rop(RzCore *core, const char *greparg, int regexp, RzC
rz_cmd_state_output_array_end(state);
rz_cons_break_pop();
rz_list_free(rx_list);
rz_asm_op_free(asmop);
rz_list_free(end_list);
rz_list_free(boundaries);
free(grep_arg);
Expand Down
30 changes: 30 additions & 0 deletions test/db/cmd/cmd_rop
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,27 @@ EXPECT=<<EOF
0x000000bb b900000000 mov ecx, 0
0x000000c0 cd80 int 0x80
0x000000c2 c3 ret
Gadget size: 15

0x000000b5 80b801000000b9 cmp byte [eax + 1], 0xb9
0x000000bc 0000 add byte [eax], al
0x000000be 0000 add byte [eax], al
0x000000c0 cd80 int 0x80
0x000000c2 c3 ret
Gadget size: 14

0x000000b7 0100 add dword [eax], eax
0x000000b9 0000 add byte [eax], al
0x000000bb b900000000 mov ecx, 0
0x000000c0 cd80 int 0x80
0x000000c2 c3 ret
Gadget size: 12

0x000000b8 0000 add byte [eax], al
0x000000ba 00b900000000 add byte [ecx], bh
0x000000c0 cd80 int 0x80
0x000000c2 c3 ret
Gadget size: 11

EOF
RUN
Expand All @@ -78,12 +82,14 @@ EXPECT=<<EOF
0x000000bb b900000000 mov ecx, 0
0x000000c0 cd80 int 0x80
0x000000c2 c3 ret
Gadget size: 15

0x000000b7 0100 add dword [eax], eax
0x000000b9 0000 add byte [eax], al
0x000000bb b900000000 mov ecx, 0
0x000000c0 cd80 int 0x80
0x000000c2 c3 ret
Gadget size: 12

EOF
RUN
Expand Down Expand Up @@ -118,17 +124,20 @@ EXPECT=<<EOF
0x000000bb b900000000 mov ecx, 0
0x000000c0 cd80 int 0x80
0x000000c2 c3 ret
Gadget size: 15

0x000000b7 0100 add dword [eax], eax
0x000000b9 0000 add byte [eax], al
0x000000bb b900000000 mov ecx, 0
0x000000c0 cd80 int 0x80
0x000000c2 c3 ret
Gadget size: 12

0x000000b8 0000 add byte [eax], al
0x000000ba 00b900000000 add byte [ecx], bh
0x000000c0 cd80 int 0x80
0x000000c2 c3 ret
Gadget size: 11

EOF
RUN
Expand Down Expand Up @@ -160,23 +169,27 @@ EXPECT=<<EOF
0x000000bb b900000000 mov ecx, 0
0x000000c0 cd80 int 0x80
0x000000c2 c3 ret
Gadget size: 15

0x000000b5 80b801000000b9 cmp byte [eax + 1], 0xb9
0x000000bc 0000 add byte [eax], al
0x000000be 0000 add byte [eax], al
0x000000c0 cd80 int 0x80
0x000000c2 c3 ret
Gadget size: 14

0x000000b7 0100 add dword [eax], eax
0x000000b9 0000 add byte [eax], al
0x000000bb b900000000 mov ecx, 0
0x000000c0 cd80 int 0x80
0x000000c2 c3 ret
Gadget size: 12

0x000000b8 0000 add byte [eax], al
0x000000ba 00b900000000 add byte [ecx], bh
0x000000c0 cd80 int 0x80
0x000000c2 c3 ret
Gadget size: 11

EOF
RUN
Expand All @@ -201,6 +214,7 @@ EXPECT=<<EOF
0x0804835e 6690 nop
0x08048360 8b1c24 mov ebx, dword [esp]
0x08048363 c3 ret
Gadget size: 20

EOF
RUN
Expand All @@ -214,6 +228,7 @@ EXPECT=<<EOF
0x08048424 56 push esi
0x08048425 53 push ebx
0x08048426 e805ffffff call 0x8048330
Gadget size: 10

EOF
RUN
Expand All @@ -230,6 +245,7 @@ EXPECT=<<EOF
0x08048424 56 push esi
0x08048425 53 push ebx
0x08048426 e805ffffff call 0x8048330
Gadget size: 10

EOF
RUN
Expand All @@ -249,83 +265,97 @@ EXPECT=<<EOF
0x00000012 e6e3 ldi r30, 0x36
0x00000014 f4e3 ldi r31, 0x34
0x00000016 02c0 rjmp 0x1c
Gadget size: 10

0x00000020 d9f7 brne 0x18
0x00000022 22e0 ldi r18, 0x02
0x00000024 a4e1 ldi r26, 0x14
0x00000026 b2e0 ldi r27, 0x02
0x00000028 01c0 rjmp 0x2c
Gadget size: 10

0x00000030 e1f7 brne 0x2a
0x00000032 10e0 ldi r17, 0x00
0x00000034 c2e6 ldi r28, 0x62
0x00000036 d0e0 ldi r29, 0x00
0x00000038 04c0 rjmp 0x42
Gadget size: 10

0x00000072 6ce0 ldi r22, 0x0c
0x00000074 71e0 ldi r23, 0x01
0x00000076 8fe1 ldi r24, 0x1f
0x00000078 92e0 ldi r25, 0x02
0x0000007a 0e946b04 call 0x8d6
Gadget size: 12

0x00000098 a701 movw r20, r14
0x0000009a 6ae0 ldi r22, 0x0a
0x0000009c 8fe1 ldi r24, 0x1f
0x0000009e 92e0 ldi r25, 0x02
0x000000a0 0e94d808 call 0x11b0
Gadget size: 12

0x000000c4 1082 st Z, r1
0x000000c6 60e0 ldi r22, 0x00
0x000000c8 71e0 ldi r23, 0x01
0x000000ca c801 movw r24, r16
0x000000cc 0e949816 call 0x2d30
Gadget size: 12

0x000000d4 6de1 ldi r22, 0x1d
0x000000d6 71e0 ldi r23, 0x01
0x000000d8 8fe1 ldi r24, 0x1f
0x000000da 92e0 ldi r25, 0x02
0x000000dc 0e946b04 call 0x8d6
Gadget size: 12

0x000000de 6b04 cpc r6, r11
0x000000e0 81e0 ldi r24, 0x01
0x000000e2 90e0 ldi r25, 0x00
0x000000e4 08c0 rjmp 0xf6
Gadget size: 8

0x000000e6 66e4 ldi r22, 0x46
0x000000e8 71e0 ldi r23, 0x01
0x000000ea 8fe1 ldi r24, 0x1f
0x000000ec 92e0 ldi r25, 0x02
0x000000ee 0e946b04 call 0x8d6
Gadget size: 12

0x00000112 6de6 ldi r22, 0x6d
0x00000114 71e0 ldi r23, 0x01
0x00000116 8fe1 ldi r24, 0x1f
0x00000118 92e0 ldi r25, 0x02
0x0000011a 0e946b04 call 0x8d6
Gadget size: 12

0x00000126 6fe7 ldi r22, 0x7f
0x00000128 71e0 ldi r23, 0x01
0x0000012a 8fe1 ldi r24, 0x1f
0x0000012c 92e0 ldi r25, 0x02
0x0000012e 0e946b04 call 0x8d6
Gadget size: 12

0x0000013a 6de6 ldi r22, 0x6d
0x0000013c 71e0 ldi r23, 0x01
0x0000013e 8fe1 ldi r24, 0x1f
0x00000140 92e0 ldi r25, 0x02
0x00000142 0e946b04 call 0x8d6
Gadget size: 12

0x0000015a 6fe7 ldi r22, 0x7f
0x0000015c 71e0 ldi r23, 0x01
0x0000015e 8fe1 ldi r24, 0x1f
0x00000160 92e0 ldi r25, 0x02
0x00000162 0e946b04 call 0x8d6
Gadget size: 12

0x000001b6 1082 st Z, r1
0x000001b8 6fe8 ldi r22, 0x8f
0x000001ba 71e0 ldi r23, 0x01
0x000001bc c801 movw r24, r16
0x000001be 0e949816 call 0x2d30
Gadget size: 12

EOF
EXPECT_ERR=<<EOF
Expand Down

0 comments on commit bb2ca7e

Please sign in to comment.