mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-11-17 22:30:17 +02:00
eeshow/gui/ (aoi_hover): could cause an access after free
This commit is contained in:
parent
dbcacbde0c
commit
eeda1c1700
@ -57,7 +57,15 @@ static bool in_aoi(const struct aoi *aoi, int x, int y)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool aoi_hover(const struct aoi *aois, int x, int y)
|
/*
|
||||||
|
* We need a pointer to the anchor of the AoI list here because dehovering may
|
||||||
|
* delete the AoI *aois points to.
|
||||||
|
*
|
||||||
|
* We could just check if hovering == *aois, but that seems risky, because
|
||||||
|
* hover(..., 0) may destroy more than just the AoI being dehovered.
|
||||||
|
*/
|
||||||
|
|
||||||
|
bool aoi_hover(struct aoi *const *aois, int x, int y)
|
||||||
{
|
{
|
||||||
const struct aoi *aoi;
|
const struct aoi *aoi;
|
||||||
|
|
||||||
@ -68,7 +76,7 @@ bool aoi_hover(const struct aoi *aois, int x, int y)
|
|||||||
hovering = NULL;
|
hovering = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (aoi = aois; aoi; aoi = aoi->next)
|
for (aoi = *aois; aoi; aoi = aoi->next)
|
||||||
if (aoi->hover && in_aoi(aoi, x, y) &&
|
if (aoi->hover && in_aoi(aoi, x, y) &&
|
||||||
aoi->hover(aoi->user, 1)) {
|
aoi->hover(aoi->user, 1)) {
|
||||||
hovering = aoi;
|
hovering = aoi;
|
||||||
@ -118,12 +126,14 @@ void aoi_set_related(struct aoi *aoi, const struct aoi *related)
|
|||||||
|
|
||||||
void aoi_remove(struct aoi **aois, const struct aoi *aoi)
|
void aoi_remove(struct aoi **aois, const struct aoi *aoi)
|
||||||
{
|
{
|
||||||
|
assert(aoi);
|
||||||
if (hovering == aoi) {
|
if (hovering == aoi) {
|
||||||
aoi->hover(aoi->user, 0);
|
aoi->hover(aoi->user, 0);
|
||||||
hovering = NULL;
|
hovering = NULL;
|
||||||
}
|
}
|
||||||
while (*aois != aoi)
|
while (*aois && *aois != aoi)
|
||||||
aois = &(*aois)->next;
|
aois = &(*aois)->next;
|
||||||
|
assert(*aois);
|
||||||
*aois = aoi->next;
|
*aois = aoi->next;
|
||||||
free((void *) aoi);
|
free((void *) aoi);
|
||||||
}
|
}
|
||||||
@ -135,4 +145,3 @@ void aoi_dehover(void)
|
|||||||
hovering->hover(hovering->user, 0);
|
hovering->hover(hovering->user, 0);
|
||||||
hovering = NULL;
|
hovering = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ struct aoi {
|
|||||||
|
|
||||||
struct aoi *aoi_add(struct aoi **aois, const struct aoi *cfg);
|
struct aoi *aoi_add(struct aoi **aois, const struct aoi *cfg);
|
||||||
void aoi_update(struct aoi *aoi, const struct aoi *cfg);
|
void aoi_update(struct aoi *aoi, const struct aoi *cfg);
|
||||||
bool aoi_hover(const struct aoi *aois, int x, int y);
|
bool aoi_hover(struct aoi *const *aois, int x, int y);
|
||||||
|
|
||||||
bool aoi_click(const struct aoi *aois, int x, int y);
|
bool aoi_click(const struct aoi *aois, int x, int y);
|
||||||
|
|
||||||
|
@ -217,7 +217,7 @@ static bool history_hover_update(void *user, int x, int y)
|
|||||||
{
|
{
|
||||||
struct gui_ctx *ctx = user;
|
struct gui_ctx *ctx = user;
|
||||||
|
|
||||||
return aoi_hover(ctx->aois, x, y);
|
return aoi_hover(&ctx->aois, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -419,9 +419,9 @@ static bool sheet_hover_update(void *user, int x, int y)
|
|||||||
curr_sheet = find_corresponding_sheet(ctx->old_hist->sheets,
|
curr_sheet = find_corresponding_sheet(ctx->old_hist->sheets,
|
||||||
ctx->new_hist->sheets, ctx->curr_sheet);
|
ctx->new_hist->sheets, ctx->curr_sheet);
|
||||||
|
|
||||||
if (aoi_hover(ctx->aois, x, y))
|
if (aoi_hover(&ctx->aois, x, y))
|
||||||
return 1;
|
return 1;
|
||||||
return aoi_hover(curr_sheet->aois,
|
return aoi_hover(&curr_sheet->aois,
|
||||||
ex + curr_sheet->xmin, ey + curr_sheet->ymin);
|
ex + curr_sheet->xmin, ey + curr_sheet->ymin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user