[PATCH 1/2] Fix SIGSEGV in dlabel feature (#556390)

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

 



g_slist_alloc is only used to create a new entry in the list and it is not
needed to initialize the list (it actually inserted an empty item at the
beginning of the list).

Also use strdup to store a copy of the device name (+ cleanup code)
---
 loader/driverdisk.c |   11 ++++-------
 loader/loader.c     |    7 +++++++
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/loader/driverdisk.c b/loader/driverdisk.c
index e2acbc8..769d075 100644
--- a/loader/driverdisk.c
+++ b/loader/driverdisk.c
@@ -841,20 +841,17 @@ GSList* findDriverDiskByLabel(void)
         return NULL;
     }
 
-    if ((ddDevice = g_slist_alloc())==NULL) {
-        logMessage(ERROR, "Cannot allocate space for list of devices");
-        return NULL;
-    }
-
     bIter = blkid_dev_iterate_begin(bCache);
     blkid_dev_set_search(bIter, "LABEL", ddLabel);
     while ((res = blkid_dev_next(bIter, &bDev)) == 0) {
         bDev = blkid_verify(bCache, bDev);
         if (!bDev)
             continue;
+
+        char *devname = strdup(blkid_dev_devname(bDev));
         logMessage(DEBUGLVL, "Adding driver disc %s to the list "
-                             "of available DDs.", blkid_dev_devname(bDev));
-        ddDevice = g_slist_prepend(ddDevice, (gpointer)blkid_dev_devname(bDev));
+                             "of available DDs.", devname);
+        ddDevice = g_slist_prepend(ddDevice, (gpointer)devname);
         /* Freeing bDev is taken care of by the put cache call */
     }
     blkid_dev_iterate_end(bIter);
diff --git a/loader/loader.c b/loader/loader.c
index d8d5fd5..9bf7c2f 100644
--- a/loader/loader.c
+++ b/loader/loader.c
@@ -1971,12 +1971,19 @@ int main(int argc, char ** argv) {
         dd = findDriverDiskByLabel();
         dditer = dd;
         while(dditer) {
+            /* load the DD */
             if (loadDriverDiskFromPartition(&loaderData, (char*)(dditer->data))) {
                 logMessage(ERROR, "Automatic driver disk loader failed for %s.", (char*)(dditer->data));
             }
             else {
                 logMessage(INFO, "Automatic driver disk loader succeeded for %s.", (char*)(dditer->data));
             }
+            
+            /* clean the device record */
+            free((char*)(dditer->data));
+            dditer->data = NULL;
+
+            /* next DD */
             dditer = g_slist_next(dditer);
         }
         g_slist_free(dd);
-- 
1.6.6

_______________________________________________
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