kmodloader: Check module endian before loading
[project/ubox.git] / kmodloader.c
index 3b7ec8b0f59cdc09180fad76fd978e4abd689072..a6aa795a81d495d37911ea16d41c7c211dc231af 100644 (file)
@@ -214,6 +214,19 @@ static int elf32_find_section(char *map, const char *section, unsigned int *offs
 static int elf_find_section(char *map, const char *section, unsigned int *offset, unsigned int *size)
 {
        int clazz = map[EI_CLASS];
+       int endian = map[EI_DATA];
+
+#if defined(__LITTLE_ENDIAN)
+       if (endian != ELFDATA2LSB)
+#elif defined(__BIG_ENDIAN)
+       if (endian != ELFDATA2MSB)
+#else
+#error "unsupported endian"
+#endif
+       {
+               ULOG_ERR("invalid endianess: %d\n", endian);
+               return -1;
+       }
 
        if (clazz == ELFCLASS32)
                return elf32_find_section(map, section, offset, size);
@@ -327,7 +340,7 @@ static struct module* get_module_info(const char *module, const char *name)
        int fd = open(module, O_RDONLY);
        unsigned int offset, size;
        char *map = MAP_FAILED, *strings, *dep = NULL;
-       const char *aliases[32];
+       const char *aliases[32] = { 0 };
        int naliases = 0;
        struct module *m = NULL;
        struct stat s;