# HG changeset patch # User Paul Boddie # Date 1654557245 -7200 # Node ID 04881b15def85420412ee2e6293230d89a2938fe # Parent 2b7f6a88332e35c041c9d36e0e694af548af34a1 Renamed get_payload and introduced payload deallocation upon error. diff -r 2b7f6a88332e -r 04881b15def8 libexec/include/exec/elf.h --- a/libexec/include/exec/elf.h Mon Jun 06 01:02:59 2022 +0200 +++ b/libexec/include/exec/elf.h Tue Jun 07 01:14:05 2022 +0200 @@ -83,7 +83,7 @@ /* Return the appropriate payload object. */ -Payload *get_payload(char *buf); +Payload *exec_open_payload(char *buf); /* vim: tabstop=2 expandtab shiftwidth=2 */ diff -r 2b7f6a88332e -r 04881b15def8 libexec/lib/src/elf.cc --- a/libexec/lib/src/elf.cc Mon Jun 06 01:02:59 2022 +0200 +++ b/libexec/lib/src/elf.cc Tue Jun 07 01:14:05 2022 +0200 @@ -162,7 +162,7 @@ /* Return the appropriate payload object. */ -Payload *get_payload(char *buf) +Payload *exec_open_payload(char *buf) { switch (buf[EI_CLASS]) { diff -r 2b7f6a88332e -r 04881b15def8 libexec/lib/src/memory.cc --- a/libexec/lib/src/memory.cc Mon Jun 06 01:02:59 2022 +0200 +++ b/libexec/lib/src/memory.cc Tue Jun 07 01:14:05 2022 +0200 @@ -52,12 +52,18 @@ /* Attempt to get a payload object appropriate for a particular object size variant. */ - *payload = get_payload(buf); + *payload = exec_open_payload(buf); + + if (*payload == NULL) + return -L4_ERANGE; - if ((*payload == NULL) || - (file->size < (*payload)->header_extent()) || + if ((file->size < (*payload)->header_extent()) || (file->size < (*payload)->program_header_extent())) - return -L4_ERANGE; + { + delete *payload; + *payload = NULL; + return -L4_EIO; + } /* Obtain all loadable segments. */ @@ -74,7 +80,11 @@ file_t *rfile = client_open(filename, file_opening_flags(segment->region_flags())); if (rfile == NULL) + { + delete *payload; + *payload = NULL; return -L4_EIO; + } err = segment->fill(rfile); } @@ -82,7 +92,11 @@ err = segment->allocate(); if (err) + { + delete *payload; + *payload = NULL; return err; + } } return L4_EOK;