Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 25 Sep 2014 22:22:52 +0000 (UTC)
From:      Xin LI <delphij@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r272141 - head/contrib/hyperv/tools
Message-ID:  <201409252222.s8PMMqfS036293@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: delphij
Date: Thu Sep 25 22:22:51 2014
New Revision: 272141
URL: http://svnweb.freebsd.org/changeset/base/272141

Log:
  Refactor the code a little bit to avoid NULL deference when
  allocation was failed.
  
  Reported by:	Coverity
  CID:		1238915
  MFC after:	1 week

Modified:
  head/contrib/hyperv/tools/hv_kvp_daemon.c

Modified: head/contrib/hyperv/tools/hv_kvp_daemon.c
==============================================================================
--- head/contrib/hyperv/tools/hv_kvp_daemon.c	Thu Sep 25 22:22:48 2014	(r272140)
+++ head/contrib/hyperv/tools/hv_kvp_daemon.c	Thu Sep 25 22:22:51 2014	(r272141)
@@ -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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201409252222.s8PMMqfS036293>