mirror of
https://github.com/libimobiledevice/libimobiledevice-glue.git
synced 2026-04-17 19:27:31 +00:00
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).
This commit is contained in:
+3
-4
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user