aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@linux.intel.com>2013-01-18 09:06:26 -0800
committerH. Peter Anvin <hpa@linux.intel.com>2013-01-18 09:06:26 -0800
commit3c0af7322087a19a2b62bb96204afc7bf93172a6 (patch)
treee20297eb95572ce2b50e58a95d07589f47260352
parent02b09a09186a36381b3cbceb484d836745cd2b63 (diff)
downloadsyslinux-3c0af7322087a19a2b62bb96204afc7bf93172a6.tar.gz
syslinux-3c0af7322087a19a2b62bb96204afc7bf93172a6.tar.xz
syslinux-3c0af7322087a19a2b62bb96204afc7bf93172a6.zip
slzm: don't use floadfile()slzm
Don't use floadfile() for loading module data. The SLZM header contains both the compressed and uncompressed sizes, so we might as well just use that information to know ahead of time how much memory to allocate. Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
-rw-r--r--com32/lib/Makefile4
-rw-r--r--com32/lib/sys/module/common.c46
2 files changed, 27 insertions, 23 deletions
diff --git a/com32/lib/Makefile b/com32/lib/Makefile
index 7bedc22e..d979ab43 100644
--- a/com32/lib/Makefile
+++ b/com32/lib/Makefile
@@ -60,7 +60,7 @@ LIBLOAD_OBJS = \
syslinux/run_default.o syslinux/run_command.o \
syslinux/cleanup.o syslinux/localboot.o syslinux/runimage.o \
\
- syslinux/loadfile.o syslinux/zloadfile.o \
+ syslinux/loadfile.o syslinux/floadfile.o syslinux/zloadfile.o \
\
syslinux/load_linux.o syslinux/initramfs.o \
syslinux/initramfs_file.o syslinux/initramfs_loadfile.o \
@@ -81,10 +81,10 @@ LIBENTRY_OBJS = \
dprintf.o vdprintf.o \
\
syslinux/idle.o \
+ \
exit.o
LIBMODULE_OBJS = \
- syslinux/floadfile.o \
sys/module/common.o sys/module/elf_module.o \
sys/module/elfutils.o \
sys/module/exec.o
diff --git a/com32/lib/sys/module/common.c b/com32/lib/sys/module/common.c
index 1daa533e..7625ab77 100644
--- a/com32/lib/sys/module/common.c
+++ b/com32/lib/sys/module/common.c
@@ -110,8 +110,8 @@ again:
int image_load(struct elf_module *module)
{
void *zdata, *mdata;
- size_t zlen, mlen;
- const struct slzm_header *hdr;
+ size_t mlen;
+ struct slzm_header hdr;
FILE *f;
int zr;
int rv = -1;
@@ -124,34 +124,39 @@ int image_load(struct elf_module *module)
f = findpath(module->name);
if (!f) {
- DBG_PRINT("Could not open module file '%s'\n", module->name);
+ dprintf("%s: could not open module file\n", module->name);
goto error;
}
- if (floadfile(f, &zdata, &zlen, NULL, 0)) {
- DBG_PRINT("Could not read module file '%s'\n", module->name);
+ if (_fread(&hdr, sizeof hdr, f) != sizeof hdr) {
+ dprintf("%s: could not read module header\n",
+ module->name);
goto error;
}
- fclose(f);
- f = NULL;
-
- hdr = zdata;
- if (zlen < sizeof *hdr) {
- dprintf("%s: file too short\n", module->name);
+ if (hdr.magic[0] != SLZM_MAGIC1 || hdr.magic[1] != SLZM_MAGIC2 ||
+ hdr.platform != SLZM_PLATFORM || hdr.arch != SLZM_ARCH) {
+ dprintf("%s: bad header\n", module->name);
goto error;
}
- zlen -= sizeof *hdr;
+ zdata = malloc(hdr.zsize);
+ if (!zdata) {
+ dprintf("%s: failed to allocate zdata buffer\n",
+ module->name);
+ goto error;
+ }
- if (hdr->magic[0] != SLZM_MAGIC1 || hdr->magic[1] != SLZM_MAGIC2 ||
- hdr->platform != SLZM_PLATFORM || hdr->arch != SLZM_ARCH ||
- zlen < hdr->zsize) {
- dprintf("%s: bad header\n", module->name);
+ if (_fread(zdata, hdr.zsize, f) != hdr.zsize) {
+ dprintf("%s: failed to read module data\n",
+ module->name);
goto error;
}
- mlen = hdr->usize + 15;
+ fclose(f);
+ f = NULL;
+
+ mlen = hdr.usize + 15;
mdata = malloc(mlen);
if (!mdata) {
dprintf("%s: failed to allocate mdata buffer\n",
@@ -159,17 +164,16 @@ int image_load(struct elf_module *module)
goto error;
}
- zr = lzo1x_decompress_fast_safe((const char *)zdata + sizeof *hdr,
- hdr->zsize, mdata, &mlen, NULL);
+ zr = lzo1x_decompress_fast_safe(zdata, hdr.zsize, mdata, &mlen, NULL);
if (zr) {
dprintf("%s: decompression returned error %d\n",
module->name, zr);
goto error;
}
- if (mlen != hdr->usize) {
+ if (mlen != hdr.usize) {
dprintf("%s: decompression returned %zu bytes expected %u\n",
- module->name, mlen, hdr->usize);
+ module->name, mlen, hdr.usize);
goto error;
}