[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
[PATCH] memory allocating error handling in modstub.c
- From: HARA Hiroshi <hhara miraclelinux com>
- To: Discussion of Development and Customization of the Red Hat Linux Installer <anaconda-devel-list redhat com>
- Subject: [PATCH] memory allocating error handling in modstub.c
- Date: Fri, 02 Nov 2007 14:48:45 +0900
Hi,
I saw our anaconda was started to manage with git in
Jeremy's mail.(thanks, Jeremy)
so I used it and it's fine for me.
then I modified the patch which I have sent before.
Current insmod in anaconda has no check point after
allocating memory (malloc/strdup/realloc).
so I added such kind of check point.
I'd appreciate it if you could review this attached patch.
thank you,
diff --git a/loader2/modstubs.c b/loader2/modstubs.c
index 51bc869..69123ba 100644
--- a/loader2/modstubs.c
+++ b/loader2/modstubs.c
@@ -91,7 +91,8 @@ int ourInsmodCommand(int argc, char ** argv) {
void * modbuf = NULL;
struct stat sb;
int i;
- char *options = strdup("");
+ char * options = NULL;
+ char * tmp;
if (argc < 2) {
return usage();
@@ -100,6 +101,11 @@ int ourInsmodCommand(int argc, char ** argv) {
while (argc > 2) {
if (!strcmp(argv[1], "-p")) {
ballPath = malloc(strlen(argv[2]) + 30);
+ if (!ballPath) {
+ logMessage(ERROR, "cannot allocate memory for ballPath: %s",
+ strerror(errno));
+ return 1;
+ }
sprintf(ballPath, "%s/modules.cgz", argv[2]);
argv += 2;
argc -= 2;
@@ -143,9 +149,27 @@ int ourInsmodCommand(int argc, char ** argv) {
return 1;
}
+ options = strdup("");
+ if (!options) {
+ logMessage(ERROR, "cannot allocate memory for options: %s",
+ strerror(errno));
+ munmap(modbuf, sb.st_size);
+ close(fd);
+ return 1;
+ }
+
for (i = 2; i < argc; i++) {
- options = realloc(options,
- strlen(options) + 1 + strlen(argv[i]) + 1);
+ tmp = realloc(options,
+ strlen(options) + 1 + strlen(argv[i]) + 1);
+ if (!tmp) {
+ logMessage(ERROR, "cannot allocate memory for options: %s",
+ strerror(errno));
+ free(options);
+ munmap(modbuf, sb.st_size);
+ close(fd);
+ return 1;
+ }
+ options = tmp;
strcat(options, argv[i]);
strcat(options, " ");
}
@@ -155,6 +179,7 @@ int ourInsmodCommand(int argc, char ** argv) {
;
if (rc != 0)
logMessage(WARNING, "failed to insert module (%d)", errno);
+ free(options);
munmap(modbuf, sb.st_size);
close(fd);
return rc;
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]