Patchwork [12/14] linux-user: Re-use load_elf_image for the main binary.

login
register
mail settings
Submitter Richard Henderson
Date April 5, 2010, 6:38 p.m.
Message ID <4BBA2E0F.9090802@twiddle.net>
Download mbox | patch
Permalink /patch/49420/
State New
Headers show

Comments

Richard Henderson - April 5, 2010, 6:38 p.m.
On 04/05/2010 11:14 AM, malc wrote:
>> +            }
>> +            interp_name = malloc(eppnt->p_filesz);
> 
> malloc can fail
> 
>> +
>> +            if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) {
>> +                memcpy(interp_name, bprm_buf + eppnt->p_offset,
>> +                       eppnt->p_filesz);
>> +            } else {
>> +		retval = pread(image_fd, interp_name, eppnt->p_filesz,
> 
> Indentation seems off.

Huh.  I suspect that the whitespace fixup patch should have also
eliminated tabs.  I don't know how else that could have crept in
there, since I have tab-expansion enabled in emacs.

I'll incorporate the following into the next version.


r~

---

Patch

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 7b854e2..e8eca86 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -1327,12 +1327,15 @@  static void load_elf_image(const char *image_name, int image_fd,
                 goto exit_errmsg;
             }
             interp_name = malloc(eppnt->p_filesz);
+            if (!interp_name) {
+                goto exit_perror;
+            }
 
             if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) {
                 memcpy(interp_name, bprm_buf + eppnt->p_offset,
                        eppnt->p_filesz);
             } else {
-		retval = pread(image_fd, interp_name, eppnt->p_filesz,
+                retval = pread(image_fd, interp_name, eppnt->p_filesz,
                                eppnt->p_offset);
                 if (retval != eppnt->p_filesz) {
                     goto exit_perror;