summaryrefslogtreecommitdiff
path: root/contrib/hyperv
diff options
context:
space:
mode:
authorXin LI <delphij@FreeBSD.org>2014-09-25 22:22:51 +0000
committerXin LI <delphij@FreeBSD.org>2014-09-25 22:22:51 +0000
commita2cf0c3c6121078c00332b5beeb6277460b886b1 (patch)
tree8a8900d144307cbe5467eaa9e4971fda3150c64a /contrib/hyperv
parent0a8534f083b0ef6712369d449f7c305eb73081dc (diff)
downloadsrc-test-a2cf0c3c6121078c00332b5beeb6277460b886b1.tar.gz
src-test-a2cf0c3c6121078c00332b5beeb6277460b886b1.zip
Refactor the code a little bit to avoid NULL deference when
allocation was failed. Reported by: Coverity CID: 1238915 MFC after: 1 week
Notes
Notes: svn path=/head/; revision=272141
Diffstat (limited to 'contrib/hyperv')
-rw-r--r--contrib/hyperv/tools/hv_kvp_daemon.c23
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 eafc867b0bd07..9b321ea31e66c 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);