aboutsummaryrefslogtreecommitdiffstats
path: root/com32/lib
diff options
context:
space:
mode:
Diffstat (limited to 'com32/lib')
-rw-r--r--com32/lib/sys/module/common.c36
-rw-r--r--com32/lib/syslinux/load_linux.c49
2 files changed, 49 insertions, 36 deletions
diff --git a/com32/lib/sys/module/common.c b/com32/lib/sys/module/common.c
index 4c83789e..a589f24f 100644
--- a/com32/lib/sys/module/common.c
+++ b/com32/lib/sys/module/common.c
@@ -59,40 +59,28 @@ void print_elf_symbols(struct elf_module *module) {
FILE *findpath(char *name)
{
+ struct path_entry *entry;
char path[FILENAME_MAX];
FILE *f;
- char *p, *n;
- int i;
f = fopen(name, "rb"); /* for full path */
if (f)
return f;
- p = PATH;
-again:
- i = 0;
- while (*p && *p != ':' && i < FILENAME_MAX - 1) {
- path[i++] = *p++;
- }
-
- if (*p == ':')
- p++;
+ list_for_each_entry(entry, &PATH, list) {
+ bool slash = false;
- /* Ensure we have a '/' separator */
- if (path[i] != '/' && i < FILENAME_MAX - 1)
- path[i++] = '/';
+ /* Ensure we have a '/' separator */
+ if (entry->str[strlen(entry->str) - 1] != '/')
+ slash = true;
- n = name;
- while (*n && i < FILENAME_MAX - 1)
- path[i++] = *n++;
- path[i] = '\0';
+ snprintf(path, sizeof(path), "%s%s%s",
+ entry->str, slash ? "/" : "", name);
- f = fopen(path, "rb");
- if (f)
- return f;
-
- if (p >= PATH && p < PATH + strlen(PATH))
- goto again;
+ f = fopen(path, "rb");
+ if (f)
+ return f;
+ }
return NULL;
}
diff --git a/com32/lib/syslinux/load_linux.c b/com32/lib/syslinux/load_linux.c
index aea03058..f6e03f76 100644
--- a/com32/lib/syslinux/load_linux.c
+++ b/com32/lib/syslinux/load_linux.c
@@ -146,6 +146,7 @@ int bios_boot_linux(void *kernel_buf, size_t kernel_size,
cmdline_size = strlen(cmdline) + 1;
+ errno = EINVAL;
if (kernel_size < 2 * 512)
goto bail;
@@ -249,8 +250,10 @@ int bios_boot_linux(void *kernel_buf, size_t kernel_size,
/* Get the memory map */
mmap = syslinux_memory_map(); /* Memory map for shuffle_boot */
amap = syslinux_dup_memmap(mmap); /* Keep track of available memory */
- if (!mmap || !amap)
+ if (!mmap || !amap) {
+ errno = ENOMEM;
goto bail;
+ }
dprintf("Initial memory map:\n");
syslinux_dump_memmap(mmap);
@@ -260,8 +263,10 @@ int bios_boot_linux(void *kernel_buf, size_t kernel_size,
it's unavailable to the boot loader, which probably has already touched
some of it), or just in the amap? */
if (memlimit)
- if (syslinux_add_memmap(&amap, memlimit, -memlimit, SMT_RESERVED))
+ if (syslinux_add_memmap(&amap, memlimit, -memlimit, SMT_RESERVED)) {
+ errno = ENOMEM;
goto bail;
+ }
/* Place the kernel in memory */
@@ -342,18 +347,24 @@ int bios_boot_linux(void *kernel_buf, size_t kernel_size,
real_mode_size))
goto bail;
if (syslinux_add_memmap
- (&amap, real_mode_base, cmdline_offset + cmdline_size, SMT_ALLOC))
+ (&amap, real_mode_base, cmdline_offset + cmdline_size, SMT_ALLOC)) {
+ errno = ENOMEM;
goto bail;
+ }
/* Zero region between real mode code and cmdline */
if (syslinux_add_memmap(&mmap, real_mode_base + real_mode_size,
- cmdline_offset - real_mode_size, SMT_ZERO))
+ cmdline_offset - real_mode_size, SMT_ZERO)) {
+ errno = ENOMEM;
goto bail;
+ }
/* Command line */
if (syslinux_add_movelist(&fraglist, real_mode_base + cmdline_offset,
- (addr_t) cmdline, cmdline_size))
+ (addr_t) cmdline, cmdline_size)) {
+ errno = ENOMEM;
goto bail;
+ }
if (hdr.version >= 0x0202) {
whdr->cmd_line_ptr = real_mode_base + cmdline_offset;
} else {
@@ -369,11 +380,15 @@ int bios_boot_linux(void *kernel_buf, size_t kernel_size,
if (prot_mode_size) {
if (syslinux_add_movelist(&fraglist, prot_mode_base,
(addr_t) kernel_buf + real_mode_size,
- prot_mode_size))
+ prot_mode_size)) {
+ errno = ENOMEM;
goto bail;
+ }
if (syslinux_add_memmap(&amap, prot_mode_base, prot_mode_size,
- SMT_ALLOC))
+ SMT_ALLOC)) {
+ errno = ENOMEM;
goto bail;
+ }
}
/* Figure out the size of the initramfs, and where to put it.
@@ -399,11 +414,15 @@ int bios_boot_linux(void *kernel_buf, size_t kernel_size,
whdr->ramdisk_image = best_addr;
whdr->ramdisk_size = irf_size;
- if (syslinux_add_memmap(&amap, best_addr, irf_size, SMT_ALLOC))
+ if (syslinux_add_memmap(&amap, best_addr, irf_size, SMT_ALLOC)) {
+ errno = ENOMEM;
goto bail;
+ }
- if (map_initramfs(&fraglist, &mmap, initramfs, best_addr))
+ if (map_initramfs(&fraglist, &mmap, initramfs, best_addr)) {
+ errno = ENOMEM;
goto bail;
+ }
}
}
@@ -439,14 +458,20 @@ int bios_boot_linux(void *kernel_buf, size_t kernel_size,
*prev_ptr = best_addr;
prev_ptr = &sdp->hdr.next;
- if (syslinux_add_memmap(&amap, best_addr, size, SMT_ALLOC))
+ if (syslinux_add_memmap(&amap, best_addr, size, SMT_ALLOC)) {
+ errno = ENOMEM;
goto bail;
+ }
if (syslinux_add_movelist(&fraglist, best_addr,
- (addr_t)&sdp->hdr, sizeof sdp->hdr))
+ (addr_t)&sdp->hdr, sizeof sdp->hdr)) {
+ errno = ENOMEM;
goto bail;
+ }
if (syslinux_add_movelist(&fraglist, best_addr + sizeof sdp->hdr,
- (addr_t)sdp->data, sdp->hdr.len))
+ (addr_t)sdp->data, sdp->hdr.len)) {
+ errno = ENOMEM;
goto bail;
+ }
}
}