[rhel5-branch 3/3] Compute size of modules buffer in loader (#484092)

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

 



In hardware.c, we build a colon-separated list of module names.  The
buffer storing that string was set to a hard limit of 1024, which isn't
big enough for certain systems.  This patch changes the function to
calculate the length required of the buffer and size it with malloc()
---
 loader2/hardware.c |   29 +++++++++++++++++++++++++----
 1 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/loader2/hardware.c b/loader2/hardware.c
index 2cea886..348ceb7 100644
--- a/loader2/hardware.c
+++ b/loader2/hardware.c
@@ -249,7 +249,7 @@ int busProbe(moduleInfoSet modInfo, moduleList modLoaded, moduleDeps modDeps,
              int justProbe) {
     int i;
     char ** modList;
-    char modules[1024];
+    char *modules = NULL;
     
     /* we always want to try to find out about pcmcia controllers even
      * if using noprobe */
@@ -268,18 +268,39 @@ int busProbe(moduleInfoSet modInfo, moduleList modLoaded, moduleDeps modDeps,
                 printf("%s\n", modList[i]);
         } else if (modList) {
             int probeVirtioAgain = 0;
+            int len = 0;
+
+            /* compute length of colon-separated string */
+            for (i = 0; modList[i]; i++) {
+                if (i) {
+                    len += 1;    /* ':' between each module name */
+                }
+
+                len += strlen(modList[i]);
+            }
+
+            len += 1;            /* '\0' at the end */
+
+            if ((modules = malloc(len)) == NULL) {
+                logMessage(ERROR, "error building modules string");
+                return 0;
+            }
 
             *modules = '\0';
-            
+
             for (i = 0; modList[i]; i++) {
-                if (i) strcat(modules, ":");
-                strcat(modules, modList[i]);
+                if (i) {
+                    modules = strcat(modules, ":");
+                }
+
+                modules = strcat(modules, modList[i]);
 
                 if (!strcmp(modList[i], "virtio_pci"))
                     probeVirtioAgain = 1;
             }
             
             mlLoadModuleSet(modules, modLoaded, modDeps, modInfo);
+            free(modules);
 
             if (probeVirtioAgain)
                 probeVirtio(modInfo, modLoaded, modDeps);
-- 
1.6.2.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