diff options
author | 2024-10-21 12:27:40 +0200 | |
---|---|---|
committer | 2024-10-21 12:33:06 +0200 | |
commit | 1085e461a58b61936ab9ffd05e33c69fd072b739 (patch) | |
tree | 588a36732bf2c8a66c2b10b89fc380252a82dc7a | |
parent | 69f98e35d68285eda3ab0f45ccc5de625d79e8f7 (diff) | |
download | libimobiledevice-glue-1085e461a58b61936ab9ffd05e33c69fd072b739.tar.gz libimobiledevice-glue-1085e461a58b61936ab9ffd05e33c69fd072b739.tar.bz2 |
socket/win32: Use calloc where applicable in getifaddrs implementation
This should prevent crashes like the one mentioned in #12 which are caused
by releasing an invalid pointer (due to uninitialized memory).
-rw-r--r-- | src/socket.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/socket.c b/src/socket.c index 6e65c42..100562c 100644 --- a/src/socket.c +++ b/src/socket.c @@ -669,7 +669,7 @@ static int getifaddrs(struct ifaddrs** ifap) } if (!ifa) { - ifa = malloc(sizeof(struct ifaddrs)); + ifa = calloc(1, sizeof(struct ifaddrs)); if (!ifa) { errno = ENOMEM; free(pAddresses); @@ -678,7 +678,7 @@ static int getifaddrs(struct ifaddrs** ifap) *ifap = ifa; ifa->ifa_next = NULL; } else { - struct ifaddrs* ifanew = malloc(sizeof(struct ifaddrs)); + struct ifaddrs* ifanew = calloc(1, sizeof(struct ifaddrs)); if (!ifanew) { freeifaddrs(*ifap); free(pAddresses); @@ -708,8 +708,7 @@ static int getifaddrs(struct ifaddrs** ifap) memcpy(ifa->ifa_addr, unicast->Address.lpSockaddr, unicast->Address.iSockaddrLength); /* netmask */ - ifa->ifa_netmask = (struct sockaddr*)malloc(sizeof(struct sockaddr_storage)); - memset(ifa->ifa_netmask, 0, sizeof(struct sockaddr_storage)); + ifa->ifa_netmask = (struct sockaddr*)calloc(1, sizeof(struct sockaddr_storage)); /* store mac address */ if (adapter->PhysicalAddressLength == 6) { |