forked from xinyu391/zircon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ulib][mdns] Remove double free in mdns_free_message.
This commit removes a free of `m->answers->name`. As reported in issue ZX-2430, `name` isn't a pointer but a fixed length array[0]. `m->answers->name` decays into a pointer when passed to `free`, which points to the same place as `m->answers`, which is also freed in the next instruction. This bug was found by Aaron while running static analysis. ASan was not able to detect it during tests because the code path was not triggered in unit tests. The issue there was that the tests that added multiple answers to a message did not call `mdns_free_messages`. I added a destructor for the struct that holds the test data, so the message will be freed after it goes out of scope. Steps to compile & reproduce: ```shell $ ./scripts/build-zircon -A -a x64 $ ./scripts/run-zircon -A -a x64 -c \ zircon.autorun.boot=/boot/test/sys/mdns-test ``` NOTE that to repro the double free issue, you need to revert the code change in `mdns.c`. ZX-2430 #done [0]: https://fuchsia.googlesource.com/zircon/+/533e8736a9d9640fccd3cb66e400b68449087149/system/ulib/mdns/include/mdns/mdns.h#129 TEST=Compiled with ASan, run unit tests as described in commit message. Change-Id: I600a39170d3a284e6ef5250769097a7db3f6e564
- Loading branch information
1 parent
4005f08
commit c9bff26
Showing
2 changed files
with
9 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters