mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-07-06 06:21:31 +00:00
perf annotate browser: Fix segfault when drawing out-of-bounds jumps
Factorize jump sanity checks from mark_jump_targets() and draw_current_jump() in an is_valid_jump() function. This fixes a segfault when moving the cursor over an invalid jump. Signed-off-by: Frederik Deweerdt <frederik.deweerdt@xprog.eu> Cc: Namhyung Kim <namhyung@kernel.org> Link: http://lkml.kernel.org/r/20130114194716.GA4973@ks398093.ip-192-95-24.net [ committer note: Make it a disasm_line method ] Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
2c803e5248
commit
865c66c418
1 changed files with 13 additions and 12 deletions
|
@ -182,6 +182,16 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
|
||||||
ab->selection = dl;
|
ab->selection = dl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool disasm_line__is_valid_jump(struct disasm_line *dl, struct symbol *sym)
|
||||||
|
{
|
||||||
|
if (!dl || !dl->ins || !ins__is_jump(dl->ins)
|
||||||
|
|| !disasm_line__has_offset(dl)
|
||||||
|
|| dl->ops.target.offset >= symbol__size(sym))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static void annotate_browser__draw_current_jump(struct ui_browser *browser)
|
static void annotate_browser__draw_current_jump(struct ui_browser *browser)
|
||||||
{
|
{
|
||||||
struct annotate_browser *ab = container_of(browser, struct annotate_browser, b);
|
struct annotate_browser *ab = container_of(browser, struct annotate_browser, b);
|
||||||
|
@ -195,8 +205,7 @@ static void annotate_browser__draw_current_jump(struct ui_browser *browser)
|
||||||
if (strstr(sym->name, "@plt"))
|
if (strstr(sym->name, "@plt"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!cursor || !cursor->ins || !ins__is_jump(cursor->ins) ||
|
if (!disasm_line__is_valid_jump(cursor, sym))
|
||||||
!disasm_line__has_offset(cursor))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
target = ab->offsets[cursor->ops.target.offset];
|
target = ab->offsets[cursor->ops.target.offset];
|
||||||
|
@ -788,17 +797,9 @@ static void annotate_browser__mark_jump_targets(struct annotate_browser *browser
|
||||||
struct disasm_line *dl = browser->offsets[offset], *dlt;
|
struct disasm_line *dl = browser->offsets[offset], *dlt;
|
||||||
struct browser_disasm_line *bdlt;
|
struct browser_disasm_line *bdlt;
|
||||||
|
|
||||||
if (!dl || !dl->ins || !ins__is_jump(dl->ins) ||
|
if (!disasm_line__is_valid_jump(dl, sym))
|
||||||
!disasm_line__has_offset(dl))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (dl->ops.target.offset >= size) {
|
|
||||||
ui__error("jump to after symbol!\n"
|
|
||||||
"size: %zx, jump target: %" PRIx64,
|
|
||||||
size, dl->ops.target.offset);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
dlt = browser->offsets[dl->ops.target.offset];
|
dlt = browser->offsets[dl->ops.target.offset];
|
||||||
/*
|
/*
|
||||||
* FIXME: Oops, no jump target? Buggy disassembler? Or do we
|
* FIXME: Oops, no jump target? Buggy disassembler? Or do we
|
||||||
|
@ -921,7 +922,7 @@ out_free_offsets:
|
||||||
|
|
||||||
#define ANNOTATE_CFG(n) \
|
#define ANNOTATE_CFG(n) \
|
||||||
{ .name = #n, .value = &annotate_browser__opts.n, }
|
{ .name = #n, .value = &annotate_browser__opts.n, }
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Keep the entries sorted, they are bsearch'ed
|
* Keep the entries sorted, they are bsearch'ed
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue