diff options
author | delphij <delphij@FreeBSD.org> | 2014-09-25 22:22:51 +0000 |
---|---|---|
committer | delphij <delphij@FreeBSD.org> | 2014-09-25 22:22:51 +0000 |
commit | a16e6119cd2640251849c434dbe9251c1bb1752e (patch) | |
tree | 8a8900d144307cbe5467eaa9e4971fda3150c64a /contrib/hyperv | |
parent | 4a35f87cdfad9148d1f9588f0aeb38c29951807c (diff) | |
download | FreeBSD-src-a16e6119cd2640251849c434dbe9251c1bb1752e.zip FreeBSD-src-a16e6119cd2640251849c434dbe9251c1bb1752e.tar.gz |
Refactor the code a little bit to avoid NULL deference when
allocation was failed.
Reported by: Coverity
CID: 1238915
MFC after: 1 week
Diffstat (limited to 'contrib/hyperv')
-rw-r--r-- | contrib/hyperv/tools/hv_kvp_daemon.c | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/contrib/hyperv/tools/hv_kvp_daemon.c b/contrib/hyperv/tools/hv_kvp_daemon.c index eafc867..9b321ea 100644 --- a/contrib/hyperv/tools/hv_kvp_daemon.c +++ b/contrib/hyperv/tools/hv_kvp_daemon.c @@ -612,18 +612,17 @@ kvp_mac_to_if_name(char *mac) sdl = (struct sockaddr_dl *)(uintptr_t)ifaddrs_ptr->ifa_addr; if (sdl->sdl_type == IFT_ETHER) { buf_ptr = strdup(ether_ntoa((struct ether_addr *)(LLADDR(sdl)))); - for (i = 0; i < strlen(buf_ptr); i++) - { - buf_ptr[i] = toupper(buf_ptr[i]); - } - - if (strncmp(buf_ptr, mac, strlen(mac)) == 0) { - /* Caller will free the memory */ - if_name = strdup(ifaddrs_ptr->ifa_name); - free(buf_ptr); - break; - }else if (buf_ptr != NULL) { - free(buf_ptr); + if (buf_ptr != NULL) { + for (i = 0; i < strlen(buf_ptr); i++) + buf_ptr[i] = toupper(buf_ptr[i]); + + if (strncmp(buf_ptr, mac, strlen(mac)) == 0) { + /* Caller will free the memory */ + if_name = strdup(ifaddrs_ptr->ifa_name); + free(buf_ptr); + break; + } else + free(buf_ptr); } } } while ((ifaddrs_ptr = ifaddrs_ptr->ifa_next) != NULL); |