Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SEGFAULT caused by out-of-bounds write #1124

Merged
merged 2 commits into from
Aug 26, 2022

Conversation

arkamar
Copy link
Contributor

@arkamar arkamar commented Aug 5, 2021

This PR fixes SEGFAULT caused by out-of-bounds write which I was experiencing after update to newest version, see the commit message for broader explanation.

I also replaced graph_id variable with g->id in other commit.

arkamar added 2 commits August 5, 2021 23:02
struct graph * is already available through g variable, let's use it
directly.
Retrieve graph only when s->graph is already allocated, which also mens
that the s->graph_width is bigger than 0, and thus avoid out-of-bounds
write in graph_append function.

Prior to 594d0c8 ("Fix bug of "Graph reset when using conditional
color"") s->graph was not (re)allocated when s->graph_width and
s->graph_allocated were equal to zero, therefore, s->graph stayed equal
to nullptr. This effectively meant that graph_append function returned
immediately after call and did nothing.

This behavior changed with introduction of std::map<int, double *> graphs,
because its retrieve_graph support function allocates s->graph even for
s->graph_width equal to 0. Then, subsequent call of graph_append can
continue and the first element of the graph is set later in this
function in line:

  graph->graph[0] = f; /* add new data */

causing out-of-bounds write, as there is not enough space in array of
zero length. This write messes up internal data of memory allocator (at
least in musl libc case) and the application later segfaults in attempt
to free this memory in store_graph function.

Fixes: 594d0c8 ("Fix bug of "Graph reset when using conditional color"")
@brndnmtthws
Copy link
Owner

Thanks and sorry for the delay!

@brndnmtthws brndnmtthws merged commit f90f632 into brndnmtthws:main Aug 26, 2022
@arkamar arkamar deleted the out-of-bounds-write branch September 10, 2022 19:05
@arkamar
Copy link
Contributor Author

arkamar commented Sep 10, 2022

No problem, thanks for merge!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants