Skip to content

Commit

Permalink
Fix a delete type mismatch (deleting a sockaddr_in6* as a sockaddr*)
Browse files Browse the repository at this point in the history
This triggered ASan, saying "object passed to delete has wrong type".
This error is caused by allocating a `struct sockaddr_in6`, casting it
and deleting it as `struct sockaddr*` which has a smaller size.

BUG=None

Review-Url: https://codereview.webrtc.org/2999053002
Cr-Commit-Position: refs/heads/master@{#19401}
  • Loading branch information
oprypin authored and Commit Bot committed Aug 18, 2017
1 parent 9e0c742 commit 1ea631f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions webrtc/rtc_base/network_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@

#include "webrtc/rtc_base/network.h"

#include <stdlib.h>

#include <memory>
#include <vector>

#include "webrtc/rtc_base/checks.h"
#include "webrtc/rtc_base/nethelpers.h"
#include "webrtc/rtc_base/networkmonitor.h"
Expand Down Expand Up @@ -122,7 +125,8 @@ class NetworkTest : public testing::Test, public sigslot::has_slots<> {

struct sockaddr_in6* CreateIpv6Addr(const std::string& ip_string,
uint32_t scope_id) {
struct sockaddr_in6* ipv6_addr = new struct sockaddr_in6;
struct sockaddr_in6* ipv6_addr = static_cast<struct sockaddr_in6*>(
malloc(sizeof(struct sockaddr_in6)));
memset(ipv6_addr, 0, sizeof(struct sockaddr_in6));
ipv6_addr->sin6_family = AF_INET6;
ipv6_addr->sin6_scope_id = scope_id;
Expand Down Expand Up @@ -168,8 +172,8 @@ class NetworkTest : public testing::Test, public sigslot::has_slots<> {
struct ifaddrs* if_addr = list;
while (if_addr != nullptr) {
struct ifaddrs* next_addr = if_addr->ifa_next;
delete if_addr->ifa_addr;
delete if_addr->ifa_netmask;
free(if_addr->ifa_addr);
free(if_addr->ifa_netmask);
delete if_addr;
if_addr = next_addr;
}
Expand Down

0 comments on commit 1ea631f

Please sign in to comment.