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 in model.Tree(procs) #2015

Merged
merged 3 commits into from
May 9, 2017

Conversation

mikkeloscar
Copy link

Fixes crash in model.Tree(procs) which occurs when the list of procs
passed, isn't in the expected order. E.g. if the first element doesn't
have PPID == 0, it would crash writing to the uninitialized
parent.Children slice.

@CLAassistant
Copy link

CLAassistant commented Apr 30, 2017

CLA assistant check
All committers have signed the CLA.

@bradrydzewski
Copy link

I think this might need some unit tests, because I'm not sure it will work as desired. A process can have multiple parent nodes where ppid == 0. I don't see anything that clears the list of children. This means if we have 2 parent processes, parent process 2 will have all of parent process 1's children in the list?

I also wonder if this could be solved by sorting? The procs are created with the correct order which has me wondering if the database can return them out of order? I haven't see this issue myself, but I'm mostly tested with sqlite.

@mikkeloscar
Copy link
Author

To be completely honest I didn't fully understand the expected output of model.Tree, I just fixed it so it worked the same (as far as I could tell) without crashing.

Your explanation is helpful, is there anywhere else I can look to get a better understanding of how the tree structure should look like?

I'm using postgresql fwiw.

@bradrydzewski
Copy link

@mikkeloscar will do. I should have some more time tomorrow. Maybe I can add some initial unit tests and you can build off those when implementing the fix?

@mikkeloscar
Copy link
Author

@bradrydzewski sounds good to me! 👍

Fixes crash in model.Tree(procs) which occurs when the list of procs
passed, isn't in the expected order. E.g. if the first element doesn't
have `PPID == 0`, it would crash writing to the uninitialized
`parent.Children`.
@bradrydzewski
Copy link

can you test if adding an order by proc_pid ASC solves the issue for you?
https://github.com/drone/drone/blob/master/store/datastore/sql/postgres/sql_gen.go#L149:L166

@mikkeloscar
Copy link
Author

@bradrydzewski yes, sorting by proc_pid solves the issue for me. I have reverted the other commit and added the changes to the postgres query.

@bradrydzewski
Copy link

awesome, thanks! much appreciated

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.

None yet

3 participants