Fix several bugs in the windbg and cris. thanks to coverity

This commit is contained in:
pancake 2014-12-09 17:45:44 +01:00
parent 98b5159af9
commit 0c91c7df62
8 changed files with 61 additions and 46 deletions

View File

@ -1332,6 +1332,7 @@ print_with_operands (const struct cris_opcode *opcodep,
const struct cris_spec_reg *sregp
= spec_reg_info ((insn >> 12) & 15, disdata->distype);
if (sregp) {
if (sregp->name == NULL)
/* Should have been caught as a non-match eariler. */
*tp++ = '?';
@ -1342,6 +1343,7 @@ print_with_operands (const struct cris_opcode *opcodep,
strcpy (tp, sregp->name);
tp += strlen (tp);
}
}
}
break;

View File

@ -105,7 +105,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
mode = 2;
} else mode = 2;
} else mode = 2;
cris_parse_disassembler_options (&disasm_obj, mode);
(void)cris_parse_disassembler_options (&disasm_obj, mode);
if (a->syntax == R_ASM_SYNTAX_ATT) {
op->size = print_insn_crisv10_v32_with_register_prefix (
(bfd_vma)Offset, &disasm_obj);

View File

@ -1275,19 +1275,15 @@ static void cmd_anal_esil(RCore *core, const char *input) {
until_expr = input + 3;
else if (input[1] == 'u')
until_addr = r_num_math(core->num, input + 2);
else
until_expr = "0";
esil_step(core, until_addr, until_expr);
else until_expr = "0";
esil_step (core, until_addr, until_expr);
break;
case 'd':
if (esil)
r_anal_esil_free (esil);
r_anal_esil_free (esil);
core->anal->esil = NULL;
break;
case 'i':
if (esil)
r_anal_esil_free (esil);
r_anal_esil_free (esil);
// reinitialize
core->anal->esil = r_anal_esil_new ();
romem = r_config_get_i (core->config, "esil.romem");
@ -1296,20 +1292,20 @@ static void cmd_anal_esil(RCore *core, const char *input) {
break;
case 'k':
switch (input[1]) {
case '\0':
input = "123*";
case ' ':
if (core && core->anal && esil && esil->stats) {
char *out = sdb_querys (esil->stats, NULL, 0, input+2);
if (out) {
r_cons_printf ("%s\n", out);
free (out);
}
} else eprintf ("esil.stats is empty. Run 'aei'\n");
break;
case '-':
sdb_reset (esil->stats);
break;
case '\0':
input = "123*";
case ' ':
if (core && core->anal && esil && esil->stats) {
char *out = sdb_querys (esil->stats, NULL, 0, input+2);
if (out) {
r_cons_printf ("%s\n", out);
free (out);
}
} else eprintf ("esil.stats is empty. Run 'aei'\n");
break;
case '-':
sdb_reset (esil->stats);
break;
}
break;
case 'f':

View File

@ -69,19 +69,20 @@ static int r_debug_wind_wait (RDebug *dbg, int pid) {
kd_packet_t *pkt;
kd_stc_64 *stc;
while (1) {
wind_wait_packet(wctx, KD_PACKET_TYPE_STATE_CHANGE, &pkt);
for (;;) {
int ret = wind_wait_packet (wctx, KD_PACKET_TYPE_STATE_CHANGE, &pkt);
if (ret != KD_E_OK || !pkt)
break;
stc = (kd_stc_64 *)pkt->data;
// Handle exceptions only
if (stc->state == 0x3030) {
wind_set_cpu(wctx, stc->cpu);
free(pkt);
wind_set_cpu (wctx, stc->cpu);
free (pkt);
dbg->reason = R_DBG_REASON_INT;
break;
} else wind_continue(wctx);
} else wind_continue (wctx);
free(pkt);
}

View File

@ -43,9 +43,11 @@ R_API int r_debug_reg_sync(RDebug *dbg, int type, int write) {
r_reg_set_bytes (dbg->reg, i, buf, R_MIN(size, bufsize));
free (buf);
}
break;
// DO NOT BREAK R_REG_TYPE_ALL PLEASE
// break;
// Continue the syncronization or just stop if it was asked only for a single type of regs
} while(i++ < R_REG_TYPE_LAST && type == R_REG_TYPE_ALL);
} while ((type==R_REG_TYPE_ALL) && (i++ < R_REG_TYPE_LAST));
return R_TRUE;
}

View File

@ -28,8 +28,10 @@ static void *iob_pipe_open (const char *path) {
sa.sun_family = AF_UNIX;
strncpy (sa.sun_path, path, sizeof(sa.sun_path));
if (connect(sock, (struct sockaddr *)&sa, sizeof(struct sockaddr_un)) == -1) {
sa.sun_path[sizeof (sa.sun_path)-1] = 0;
if (connect (sock, (struct sockaddr *)&sa, sizeof(struct sockaddr_un)) == -1) {
perror ("connect");
close (sock);
return 0;
}
return (void *)(size_t)sock;

View File

@ -59,8 +59,11 @@ int iob_write (void *fp, const uint8_t *buf, const uint32_t buf_len) {
if (!sel_backend)
return E_NOIF;
for (done = 0; done < buf_len;)
done += sel_backend->write(fp, buf + done, buf_len - done, 100);
for (done = 0; done < buf_len;) {
int ret = sel_backend->write(fp, buf + done, buf_len - done, 100);
if (ret<1) break;
done += ret;
}
return done;
}
@ -71,8 +74,11 @@ int iob_read (void *fp, uint8_t *buf, const uint32_t buf_len) {
if (!sel_backend)
return E_NOIF;
for (done = 0; done < buf_len;)
done += sel_backend->read(fp, buf + done, buf_len - done, 100);
for (done = 0; done < buf_len;) {
int ret = sel_backend->read(fp, buf + done, buf_len - done, 100);
if (ret<1) break;
done += ret;
}
return done;
}

View File

@ -303,7 +303,12 @@ int wind_wait_packet (WindCtx *ctx, const uint32_t type, kd_packet_t **p) {
return ret;
}
p? *p = pkt: free(pkt);
if (p) {
*p = pkt;
} else {
free (pkt);
*p = 0;
}
return KD_E_OK;
}
@ -320,11 +325,11 @@ typedef struct {
int
wind_walk_vadtree (WindCtx *ctx, uint64_t address, uint64_t parent) {
mmvad_short entry;
mmvad_short entry = {0};
uint64_t start, end;
int prot;
if (!wind_read_at(ctx, (uint8_t *)&entry, address - 0x4, sizeof(mmvad_short))) {
if (wind_read_at(ctx, (uint8_t *)&entry, address - 0x4, sizeof(mmvad_short)) != sizeof (mmvad_short)) {
fprintf(stderr, "%llx Could not read the node!\n", address);
return 0;
}
@ -637,7 +642,8 @@ wind_sync (WindCtx *ctx) {
return 0;
// Send the breakin packet
iob_write(ctx->io_ptr, (const uint8_t*)"b", 1);
if (iob_write (ctx->io_ptr, (const uint8_t*)"b", 1) != 1)
return 0;
// Reset the host
ret = kd_send_ctrl_packet(ctx->io_ptr, KD_PACKET_TYPE_RESET, 0);
@ -688,22 +694,22 @@ wind_continue (WindCtx *ctx) {
req.r_cont.tf = 0x400;
#ifdef WIND_LOG
printf("Sending continue...\n");
fprintf (stderr, "Sending continue...\n");
#endif
ret = kd_send_data_packet(ctx->io_ptr, KD_PACKET_TYPE_MANIP, (ctx->seq_id ^= 1), (uint8_t *)&req,
sizeof(kd_req_t), NULL, 0);
ret = kd_send_data_packet (ctx->io_ptr, KD_PACKET_TYPE_MANIP, (ctx->seq_id ^= 1), (uint8_t *)&req,
sizeof (kd_req_t), NULL, 0);
if (ret != KD_E_OK)
return 0;
ret = wind_wait_packet(ctx, KD_PACKET_TYPE_ACK, NULL);
ret = wind_wait_packet (ctx, KD_PACKET_TYPE_ACK, NULL);
if (ret != KD_E_OK)
return 0;
r_list_free(ctx->plist_cache);
r_list_free (ctx->plist_cache);
ctx->plist_cache = NULL;
#ifdef WIND_LOG
printf("Done!\n");
fprintf (stderr, "Done!\n");
#endif
return 1;