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

unchecked malloc failure can cause segfault #7

Closed
totaam opened this issue Jun 3, 2016 · 5 comments
Closed

unchecked malloc failure can cause segfault #7

totaam opened this issue Jun 3, 2016 · 5 comments

Comments

@totaam
Copy link
Contributor

totaam commented Jun 3, 2016

As it is, a malicious remote user can cause a segfault during data parsing by supplying an extremely large big number, which will cause malloc to fail and then memcpy will crash on NULL.
Here's an easy fix (two commits as I messed up the first one).
http://xpra.org/trac/changeset/12729
http://xpra.org/trac/changeset/12730

This also fixes a similar issue for realloc, this time by checking the return value - you may want to use the same approach everywhere for consistency. I guess the realloc case is less critical as applications tend to encode their own data rather than data provided by a remote user, but this can still crash.

@aresch
Copy link
Owner

aresch commented Jun 5, 2016

Thanks for the report. I'm just now starting to look into this.

I think one way we could fix this is to limit the search for the CHR_TERM to MAX_INT_LENGTH. Since we only allow the encoding of a 64 character string for a big number, we shouldn't look further than that and throw an error if we don't find CHR_TERM.

Regarding the use of malloc, I'll have to investigate that a bit more and understand the performance implications either way although I think you're probably right.

@aresch
Copy link
Owner

aresch commented Jun 5, 2016

This has been fixed in 92e1ebc

I did remove the malloc as it is a better solution and was actually slightly faster in my tests.

@aresch aresch closed this as completed Jun 5, 2016
@totaam
Copy link
Contributor Author

totaam commented Jun 6, 2016

Thanks.
I think you forgot about the realloc case, a simple assert not NULL would do the job there.

@aresch aresch reopened this Jun 6, 2016
@aresch
Copy link
Owner

aresch commented Jun 6, 2016

Oh right. I'll take a look at that.

@aresch
Copy link
Owner

aresch commented Jun 7, 2016

Fixed in d3c779b

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

No branches or pull requests

2 participants