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);
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to