linux: return early if we have no interfaces
This was pointed out as possible undefined allocation of 0 bytes by clang-analyzer. `malloc` of 0 bytes can return either `NULL` or a valid pointer which can't be dereferenced. On systems which return `NULL`, we would consider it a `malloc` error and return an `ENOMEM` to the caller. PR-URL: https://github.com/libuv/libuv/pull/13 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
This commit is contained in:
parent
18d58643af
commit
f86cd02a94
@ -754,6 +754,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses,
|
||||
return -errno;
|
||||
|
||||
*count = 0;
|
||||
*addresses = NULL;
|
||||
|
||||
/* Count the number of interfaces */
|
||||
for (ent = addrs; ent != NULL; ent = ent->ifa_next) {
|
||||
@ -766,6 +767,9 @@ int uv_interface_addresses(uv_interface_address_t** addresses,
|
||||
(*count)++;
|
||||
}
|
||||
|
||||
if (*count == 0)
|
||||
return 0;
|
||||
|
||||
*addresses = malloc(*count * sizeof(**addresses));
|
||||
if (!(*addresses))
|
||||
return -ENOMEM;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user