summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToomas Soome <tsoome@me.com>2020-02-21 21:27:04 +0200
committerToomas Soome <tsoome@me.com>2020-02-24 21:07:16 +0200
commit873f5d0769a5334a9dfb27cf8a5174e25ae4418e (patch)
treeb31f745bd2d3b662bcf33f180895aceaf228f16b
parent0cad6fe6a45fed29aa5c115fda1fc16385145fce (diff)
downloadillumos-joyent-873f5d0769a5334a9dfb27cf8a5174e25ae4418e.tar.gz
12335 loader: can not load zero sized file
Reviewed by: Andy Fiddaman <andy@omniosce.org> Reviewed by: Jorge Schrauwen <jorge@blackdot.be> Approved by: Dan McDonald <danmcd@joyent.com>
-rw-r--r--usr/src/boot/Makefile.version2
-rw-r--r--usr/src/boot/sys/boot/common/module.c8
-rw-r--r--usr/src/boot/sys/boot/efi/loader/copy.c4
3 files changed, 10 insertions, 4 deletions
diff --git a/usr/src/boot/Makefile.version b/usr/src/boot/Makefile.version
index 4c3af63cb9..dd8b6a292d 100644
--- a/usr/src/boot/Makefile.version
+++ b/usr/src/boot/Makefile.version
@@ -33,4 +33,4 @@ LOADER_VERSION = 1.1
# Use date like formatting here, YYYY.MM.DD.XX, without leading zeroes.
# The version is processed from left to right, the version number can only
# be increased.
-BOOT_VERSION = $(LOADER_VERSION)-2020.02.03.1
+BOOT_VERSION = $(LOADER_VERSION)-2020.02.21.1
diff --git a/usr/src/boot/sys/boot/common/module.c b/usr/src/boot/sys/boot/common/module.c
index 14aa790973..4936ec5a3c 100644
--- a/usr/src/boot/sys/boot/common/module.c
+++ b/usr/src/boot/sys/boot/common/module.c
@@ -671,7 +671,8 @@ file_loadraw(const char *fname, char *type, int argc, char **argv, int insert)
"error reading '%s': %s", name, strerror(errno));
free(name);
close(fd);
- if (archsw.arch_free_loadaddr != NULL) {
+ if (archsw.arch_free_loadaddr != NULL &&
+ st.st_size != 0) {
archsw.arch_free_loadaddr(loadaddr,
(uint64_t)
(roundup2(st.st_size, PAGE_SIZE) >> 12));
@@ -684,7 +685,7 @@ file_loadraw(const char *fname, char *type, int argc, char **argv, int insert)
/* Looks OK so far; create & populate control structure */
fp = file_alloc();
if (fp == NULL) {
- if (archsw.arch_free_loadaddr != NULL)
+ if (archsw.arch_free_loadaddr != NULL && st.st_size != 0)
archsw.arch_free_loadaddr(loadaddr,
(uint64_t)(roundup2(st.st_size, PAGE_SIZE) >> 12));
snprintf(command_errbuf, sizeof (command_errbuf),
@@ -1151,7 +1152,8 @@ file_discard(struct preloaded_file *fp)
if (fp == NULL)
return;
- if (archsw.arch_free_loadaddr != NULL && fp->f_addr) {
+ if (archsw.arch_free_loadaddr != NULL && fp->f_addr &&
+ fp->f_size != 0) {
archsw.arch_free_loadaddr(fp->f_addr,
(uint64_t)(roundup2(fp->f_size, PAGE_SIZE) >> 12));
}
diff --git a/usr/src/boot/sys/boot/efi/loader/copy.c b/usr/src/boot/sys/boot/efi/loader/copy.c
index 0dd8e8a5cc..77a0703136 100644
--- a/usr/src/boot/sys/boot/efi/loader/copy.c
+++ b/usr/src/boot/sys/boot/efi/loader/copy.c
@@ -174,6 +174,10 @@ efi_loadaddr(uint_t type, void *data, vm_offset_t addr)
size = st.st_size;
}
+ /* AllocatePages can not allocate 0 pages. */
+ if (size == 0)
+ return (addr);
+
pages = EFI_SIZE_TO_PAGES(size);
/* 4GB upper limit */
paddr = UINT32_MAX;