[Sync] Address use-after-free in Directory::InsertEntry
Directory::InsertEntry takes pointer to EntryKernel and inserts owning pointer into methandles_mapo with WrapUnique. The object is still owned by unique_ptr in ModelNeutralMutableEntry ctor. If one if the steps inside InsertEntry fails ModelNeutralMutableEntry will not release unique_ptr which will cause object to be freed while metahandles map still has entry pointing to it. I changed InsertEntry to pass ownint pointer to EntryKernel. Caller is free to stash non-owning pointer, but has to reset it to nullptr if InsertEntry fails. I refactored couple of functions in Directory to be more strict with pointers to EntryKernel. Particularly DeleteEntry should use entry found in metahandles_map, not the entry passed as an argument to remove entry from different indices. It shouldn't matter in terms of correctness, but makes it easier to reason about the logic. BUG=705704 R=skym@chromium.org Review-Url: https://codereview.chromium.org/2844333003 Cr-Commit-Position: refs/heads/master@{#468102}
Showing
Please register or sign in to comment