Skip to content

Commit 59a9dfb

Browse files
committed
Fix uaf crash in aaft (tests_64927) ##crash
Reported by giantbranch of NSFOCUS TIANJI Lab
1 parent 65527b8 commit 59a9dfb

3 files changed

Lines changed: 15 additions & 9 deletions

File tree

libr/core/anal_tp.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -510,16 +510,16 @@ R_API void r_core_anal_type_match(RCore *core, RAnalFunction *fcn) {
510510
return;
511511
}
512512
char *pc = strdup (_pc);
513-
RRegItem *r = r_reg_get (core->dbg->reg, pc, -1);
514-
if (!r) {
515-
free (buf);
516-
return;
517-
}
518513
r_cons_break_push (NULL, NULL);
519514
r_list_sort (fcn->bbs, bb_cmpaddr); // TODO: The algorithm can be more accurate if blocks are followed by their jmp/fail, not just by address
520515
r_list_foreach (fcn->bbs, it, bb) {
521516
ut64 addr = bb->addr;
522517
int i = 0;
518+
RRegItem *r = r_reg_get (core->dbg->reg, pc, -1);
519+
if (!r) {
520+
free (buf);
521+
return;
522+
}
523523
r_reg_set_value (core->dbg->reg, r, addr);
524524
while (1) {
525525
if (r_cons_is_breaked ()) {
@@ -549,6 +549,11 @@ R_API void r_core_anal_type_match(RCore *core, RAnalFunction *fcn) {
549549
}
550550
sdb_num_set (anal->esil->trace->db, sdb_fmt ("0x%"PFMT64x".count", addr), loop_count + 1, 0);
551551
if (r_anal_op_nonlinear (aop.type)) { // skip the instr
552+
RRegItem *r = r_reg_get (core->dbg->reg, pc, -1);
553+
if (!r) {
554+
free (buf);
555+
return;
556+
}
552557
r_reg_set_value (core->dbg->reg, r, addr + ret);
553558
} else {
554559
r_core_esil_step (core, UT64_MAX, NULL, NULL, false);

libr/core/cmd_anal.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4766,7 +4766,7 @@ void cmd_anal_reg(RCore *core, const char *str) {
47664766
int size = 0, i, type = R_REG_TYPE_GPR;
47674767
int bits = (core->anal->bits & R_SYS_BITS_64)? 64: 32;
47684768
int use_colors = r_config_get_i (core->config, "scr.color");
4769-
RRegItem *r;
4769+
RRegItem *r = NULL;
47704770
const char *use_color;
47714771
const char *name;
47724772
char *arg;
@@ -5098,6 +5098,7 @@ void cmd_anal_reg(RCore *core, const char *str) {
50985098
arg = strchr (str + 1, '=');
50995099
if (arg) {
51005100
*arg = 0;
5101+
ut64 n = r_num_math (core->num, arg + 1);
51015102
char *ostr = r_str_trim_dup (str + 1);
51025103
char *regname = r_str_trim_nc (ostr);
51035104
r = r_reg_get (core->dbg->reg, regname, -1);
@@ -5113,8 +5114,7 @@ void cmd_anal_reg(RCore *core, const char *str) {
51135114
if (r) {
51145115
//eprintf ("%s 0x%08"PFMT64x" -> ", str,
51155116
// r_reg_get_value (core->dbg->reg, r));
5116-
r_reg_set_value (core->dbg->reg, r,
5117-
r_num_math (core->num, arg + 1));
5117+
r_reg_set_value (core->dbg->reg, r, n);
51185118
r_debug_reg_sync (core->dbg, R_REG_TYPE_ALL, true);
51195119
//eprintf ("0x%08"PFMT64x"\n",
51205120
// r_reg_get_value (core->dbg->reg, r));

libr/reg/rvalue.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,10 @@ R_API ut64 r_reg_get_value_by_role(RReg *reg, RRegisterId role) {
141141
}
142142

143143
R_API bool r_reg_set_value(RReg *reg, RRegItem *item, ut64 value) {
144+
r_return_val_if_fail (reg && item, false);
145+
144146
ut8 bytes[12];
145147
ut8 *src = bytes;
146-
r_return_val_if_fail (reg && item, false);
147148

148149
if (r_reg_is_readonly (reg, item)) {
149150
return true;

0 commit comments

Comments
 (0)