From b22e5bcf6009b090d5952f1c2960ee2cb109ea3e Mon Sep 17 00:00:00 2001 From: Mike McTernan Date: Thu, 7 Dec 2023 12:13:18 +0000 Subject: [PATCH] trusty: apploader: fail specifically if app package is 0 bytes Replace assert with check and log message. Also log more about the request if DMA heap allocation fails. Bug: 315283243 Test: boot to home Test: touch x && trusty_apploader x Change-Id: Ic075809fd2a6b09d9c4e8dff986709c4deae8fb7 --- trusty/apploader/apploader.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/trusty/apploader/apploader.cpp b/trusty/apploader/apploader.cpp index f782d2acb..0915eab57 100644 --- a/trusty/apploader/apploader.cpp +++ b/trusty/apploader/apploader.cpp @@ -107,7 +107,11 @@ static unique_fd read_file(const char* file_name, off64_t* out_file_size) { return {}; } - assert(st.st_size >= 0); + if (st.st_size == 0) { + LOG(ERROR) << "Zero length file '" << file_name << "'"; + return {}; + } + file_size = st.st_size; /* The dmabuf size needs to be a multiple of the page size */ @@ -123,7 +127,8 @@ static unique_fd read_file(const char* file_name, off64_t* out_file_size) { BufferAllocator alloc; unique_fd dmabuf_fd(alloc.Alloc(kDmabufSystemHeapName, file_page_size)); if (!dmabuf_fd.ok()) { - LOG(ERROR) << "Error creating dmabuf: " << dmabuf_fd.get(); + LOG(ERROR) << "Error creating dmabuf for " << file_page_size + << " bytes: " << dmabuf_fd.get(); return dmabuf_fd; }