[PATCH 1/2] Correct modopts initialization in loader (take 2) (#531932).

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

 



The edc665e6fa2ba71e89eb83412738622e916c3a05 commit prevented SIGSEGV
but changed behavior of modopts to where we'd never get any values in
modopts.

What needed to happen is the else clause in addOption() needed to
initalize the .options array and add in the option value.  That wasn't
happening, so strcat() calls in writeModulesConf() were causing SIGSEGV.

This patch also adds some realloc() and malloc() checks.  Tested with
"radeon.nomodeset=1" and without that parameter on x86_64.
---
 loader/modules.c |   43 +++++++++++++++++++++++++++++++++----------
 1 files changed, 33 insertions(+), 10 deletions(-)

diff --git a/loader/modules.c b/loader/modules.c
index f61f680..a72a40a 100644
--- a/loader/modules.c
+++ b/loader/modules.c
@@ -105,7 +105,7 @@ void mlAddBlacklist(char *module) {
 }
 
 static void addOption(const char *module, const char *option) {
-    int found = 0, i;
+    int found = 0, i, sz;
 
     found = 0;
     for (i = 0; i < nummodopts; i++) {
@@ -117,18 +117,41 @@ static void addOption(const char *module, const char *option) {
     }
 
     if (found) {
+        modopts[i].options = realloc(modopts[i].options,
+                                     sizeof(modopts[i].options) *
+                                     (modopts[i].numopts + 1));
         if (modopts == NULL) {
-            modopts = realloc(modopts, sizeof(*modopts) * (nummodopts + 1));
-            modopts[nummodopts].name = strdup(module);
-            modopts[nummodopts].numopts = 1;
-            modopts[nummodopts++].options = NULL;
+            logMessage(ERROR, "%s (%d): %m", __func__, __LINE__);
+            abort();
+        }
+
+        modopts[i].options[modopts[i].numopts - 1] = strdup(option);
+        modopts[i].options[modopts[i].numopts] = NULL;
+    } else {
+        if (modopts == NULL) {
+            modopts = malloc(sizeof(struct moduleOptions) * (nummodopts + 1));
         } else {
-            modopts[i].options = realloc(modopts[i].options,
-                                         sizeof(modopts[i].options) *
-                                         (modopts[i].numopts + 1));
-            modopts[i].options[modopts[i].numopts - 1] = strdup(option);
-            modopts[i].options[modopts[i].numopts] = NULL;
+            modopts = realloc(modopts, sizeof(*modopts) * (nummodopts + 1));
+        }
+
+        if (modopts == NULL) {
+            logMessage(ERROR, "%s (%d): %m", __func__, __LINE__);
+            abort();
         }
+
+        modopts[nummodopts].name = strdup(module);
+        modopts[nummodopts].numopts = 1;
+
+        sz = sizeof(modopts[nummodopts].options) * 2;
+        if ((modopts[nummodopts].options = malloc(sz)) == NULL) {
+            logMessage(ERROR, "%s (%d): %m", __func__, __LINE__);
+            abort();
+        }
+
+        modopts[nummodopts].options[0] = strdup(option);
+        modopts[nummodopts].options[1] = NULL;
+
+        nummodopts++;
     }
 
     return;
-- 
1.6.5.2

_______________________________________________
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