PATCH: mkinitrd: Fix various segfaults in renameNetworkInterface() (#485309)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



There are currently 3 unhandled "special" cases in renameNetworkInterface(),
all of which will cause a segfault:
1) Some type of network devices do not have a MAC (NULL pointer deref)
2) If the interface to rename already has the same name, we would use
   an uninitialized pointer (the oldname one)
3) If no interface exists with the given MAC, we would use
   an uninitialized pointer (the oldname one)

This patch fixes all 3. Note I think we should backport this to RHEL-5!
---
 nash/network.c |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/nash/network.c b/nash/network.c
index f2ea79d..125e147 100644
--- a/nash/network.c
+++ b/nash/network.c
@@ -809,7 +809,7 @@ renameNetworkInterface(char *hwaddr, char *ifname)
     int rc = 0;

     int collision = 0;
-    char *oldname;
+    char *oldname = NULL;

     /* if we're called like "netname $BOOTIF eth0", that'll expand to
      * "01-c0-ff-ee-c0-ff-ee" .  We don't want the leading "01-", and
@@ -825,14 +825,21 @@ renameNetworkInterface(char *hwaddr, char *ifname)

     if (get_ifinfo(&ifinfo) >= 0) {
         for (ifentry = ifinfo; ifentry; ifentry = ifentry->next) {
-            if (!strcasecmp(hwaddr, ifentry->mac)) {
+            if (ifentry->mac && !strcasecmp(hwaddr, ifentry->mac)) {
                 if (!strcmp(ifname, ifentry->name))
-                    break;
+                    goto leave; /* no renaming needed */
                 oldname = ifentry->name;
             } else if (!strcmp(ifname, ifentry->name)) {
                 collision = 1;
             }
         }
+
+        if (!oldname) {
+            eprintf("No interface with MAC: %s found\n", hwaddr);
+            rc = -1;
+            goto leave;
+        }
+
         if (collision)
             rc = do_changename(ifname, "nashdevname");
         if (rc >= 0)
@@ -840,6 +847,7 @@ renameNetworkInterface(char *hwaddr, char *ifname)
         if (rc >= 0 && collision)
             rc = do_changename("nashdevname", oldname);

+leave:
         free_ifinfo(ifinfo);
     }

--
1.6.1.3

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux