More error checking when trying to open files in
authorPatrick Georgi <patrick.georgi@coresystems.de>
Tue, 15 Sep 2009 08:21:46 +0000 (08:21 +0000)
committerPatrick Georgi <patrick.georgi@coresystems.de>
Tue, 15 Sep 2009 08:21:46 +0000 (08:21 +0000)
cbfstool. (trivial)

Signed-off-by: Patrick Georgi <patrick.georgi@coresystems.de>
Acked-by: Patrick Georgi <patrick.georgi@coresystems.de>
git-svn-id: svn://svn.coreboot.org/coreboot/trunk@4634 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1

util/cbfstool/cbfstool.c
util/cbfstool/common.c

index 637bddb1fcb26af06369b0c9101b07a2b0af9c57..1862af4e2566740776147f7a22b3b1fe006912f1 100644 (file)
@@ -57,6 +57,10 @@ int main(int argc, char **argv)
        }
 
        void *rom = loadrom(romname);
+       if (rom == NULL) {
+               printf("Could not load ROM image '%s'.\n", romname);
+               return 1;
+       }
 
        if (strcmp(cmd, "print") == 0) {
                print_cbfs_directory(romname);
@@ -68,11 +72,15 @@ int main(int argc, char **argv)
                return 1;
        }
 
-       void *filename = argv[3];
-       void *cbfsname = argv[4];
+       char *filename = argv[3];
+       char *cbfsname = argv[4];
 
        uint32_t filesize = 0;
        void *filedata = loadfile(filename, &filesize, 0, SEEK_SET);
+       if (filedata == NULL) {
+               printf("Could not load file '%s'.\n", filename);
+               return 1;
+       }
 
        uint32_t base = 0;
        void *cbfsfile;
index 8db2d8cfe3beda6a300b183d6b5c5eddfb4e7fd1..9227337c57a6c6aff9f5440ffb3601e9458bcab3 100644 (file)
@@ -31,6 +31,8 @@ void *loadfile(const char *filename, uint32_t * romsize_p, void *content,
               int place)
 {
        FILE *file = fopen(filename, "rb");
+       if (file == NULL)
+               return NULL;
        fseek(file, 0, SEEK_END);
        *romsize_p = ftell(file);
        fseek(file, 0, SEEK_SET);
@@ -65,6 +67,8 @@ void recalculate_rom_geometry(void *romarea)
 void *loadrom(const char *filename)
 {
        void *romarea = loadfile(filename, &romsize, 0, SEEK_SET);
+       if (romarea == NULL)
+               return NULL;
        recalculate_rom_geometry(romarea);
        return romarea;
 }