fix double-free by implicit interface or early termination#1305
Merged
Conversation
Contributor
|
I really trust you there :D |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #1302
This pull request fixes two double-free conditions.
First of all, during startup, Ettercap is filtering the list of useful interfaces returned by libpcap's
pcap_findalldevs(). Its doing so by allocating memory to hold thepcap_if_tstructures including all its contents:This shortened single-linked list is then stored under
EC_GBL_PCAP->ifs.However, the trap here is, that the structure also holds pointers allocated during libpcap's
pcap_findalldevs(), like name or description. The above code, copies them 1:1, including these struct-members' values.Now, if no interface is specified
-i, the memory address of the name member (pointer), allocated within libpcap, is copied to the global variableEC_GBL_OPTIONS->ifacea.k.a.ec_gbls->options->iface:Since the memory was allocated by libpcap, the call of
pcap_freealldevs()frees this memory. Subsequently,EC_GBL_OPTIONS->ifaceis freed again, leading to the first double-free condition:The second one is similar:
Only
devwas allocated by Ettercap in any case.dev->descriptiononly if libpcap didn't provide any description.But when the description member was set by libpcap, the pointer in the original
pcap_if_tstructure points to the memory independently. EvenSAFE_FREE(dev->description);doesn't help, since its only setting the copied member pointer to NULL, the original still points to the memory which just got freed.I checked the source code of
pcap_freealldevs(). Sincepcap_freealldevs()freesdev->descriptiononly if its not NULL, we don't need to freedev->descriptionseparately providing us with a elegant fix to this issue..