Skip to content
This repository has been archived by the owner on Aug 3, 2024. It is now read-only.

Fix xdg surface use-after-free by switching to NonNull #280

Merged
merged 4 commits into from
Feb 27, 2019

Conversation

Timidger
Copy link
Member

@Timidger Timidger commented Feb 22, 2019

There was a use-after-free if yad --entry was ran in a compositor and then killed with SIGTERM (e.g. with ^C). This was because it was using the internal resource again when it upgraded the data.

The first commit of this patch series is a naive fix. The rest of the commits are doing it better by changing how Handle stores its data. It now stores a Option<D>. This was done because we needed a default for D but Default isn't implemented for raw pointers (which most Ds were).

However, since D was always a pointer it could have been null this would have added overhead. To keep the cost down, and because it was a big change already, I also switched all the internal pointers over to NonNulls. This added some noise in the code, but makes it much more difficult to have these sort of errors hopefully.

Now we return an Option so we have to check it. This introduces overhead
that will be removed by switching to NonNull.

The one downside is one ugly, ugly thing:

Some(OptionalShellState(match self.state {
      None => None,
       Some(ref state) => Some(unsafe { state.clone() })
}))

This is a Some of an optional wrapper...so yeah it's really inefficient
and ugly in order to make it so that users can't clone shell states.
This is more efficient in terms of Option space compression, and it's
safer. Though it's more verbose internally.
@Timidger
Copy link
Member Author

Switched everything over to use NonNull which fixes #283

@Timidger Timidger changed the title [WIP] Hot fix for xdg surface use-after-free Fix xdg surface use-after-free by switching to NonNull Feb 27, 2019
@Timidger Timidger merged commit 786b2d7 into master Feb 27, 2019
@Timidger Timidger deleted the xdg-surface-fix branch February 27, 2019 23:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging this pull request may close these issues.

None yet

1 participant