[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
[rhel5-branch 3/5] Compute size of modules buffer in loader (#484092)
- From: David Cantrell <dcantrell redhat com>
- To: anaconda-devel-list redhat com
- Cc:
- Subject: [rhel5-branch 3/5] Compute size of modules buffer in loader (#484092)
- Date: Fri, 1 May 2009 11:22:10 -1000
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 resize it with
realloc().
---
loader2/hardware.c | 34 ++++++++++++++++++++++++++++------
1 files changed, 28 insertions(+), 6 deletions(-)
diff --git a/loader2/hardware.c b/loader2/hardware.c
index 2cea886..7c574eb 100644
--- a/loader2/hardware.c
+++ b/loader2/hardware.c
@@ -247,9 +247,9 @@ int earlyModuleLoad(moduleInfoSet modInfo, moduleList modLoaded,
int busProbe(moduleInfoSet modInfo, moduleList modLoaded, moduleDeps modDeps,
int justProbe) {
- int i;
+ int i, len = 0;
char ** modList;
- char modules[1024];
+ char *modules = NULL;
/* we always want to try to find out about pcmcia controllers even
* if using noprobe */
@@ -269,17 +269,39 @@ int busProbe(moduleInfoSet modInfo, moduleList modLoaded, moduleDeps modDeps,
} else if (modList) {
int probeVirtioAgain = 0;
- *modules = '\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 */
+
for (i = 0; modList[i]; i++) {
- if (i) strcat(modules, ":");
- strcat(modules, modList[i]);
+ if (i > 0) {
+ modules = strncat(modules, ":", 1);
+ }
+
+ if (modules == NULL) {
+ modules = strdup(modList[i]);
+
+ if ((modules = realloc(modules, len)) == NULL) {
+ logMessage(ERROR, "error building modules string");
+ return 0;
+ }
+ } else {
+ modules = strncat(modules, modList[i], strlen(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
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]