From patchwork Mon Apr 5 18:38:07 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 49420 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A4D45B7CF3 for ; Tue, 6 Apr 2010 04:58:09 +1000 (EST) Received: from localhost ([127.0.0.1]:44200 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NyrR2-0001Sg-Po for incoming@patchwork.ozlabs.org; Mon, 05 Apr 2010 14:54:08 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NyrOF-00017i-Ml for qemu-devel@nongnu.org; Mon, 05 Apr 2010 14:51:15 -0400 Received: from [140.186.70.92] (port=40681 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NyrN1-0000Ul-Rc for qemu-devel@nongnu.org; Mon, 05 Apr 2010 14:50:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NyrBY-0001Jp-UO for qemu-devel@nongnu.org; Mon, 05 Apr 2010 14:38:14 -0400 Received: from are.twiddle.net ([75.149.56.221]:37811) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NyrBY-0001Je-Om for qemu-devel@nongnu.org; Mon, 05 Apr 2010 14:38:08 -0400 Received: from anchor.twiddle.home (anchor.twiddle.home [172.31.0.4]) by are.twiddle.net (Postfix) with ESMTPSA id 941D634; Mon, 5 Apr 2010 11:38:07 -0700 (PDT) Message-ID: <4BBA2E0F.9090802@twiddle.net> Date: Mon, 05 Apr 2010 11:38:07 -0700 From: Richard Henderson User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100330 Fedora/3.0.4-1.fc12 Thunderbird/3.0.4 MIME-Version: 1.0 To: malc Subject: Re: [Qemu-devel] [PATCH 12/14] linux-user: Re-use load_elf_image for the main binary. References: <878d3e21b6ae87a80fda3a4653a3a2ba8e1e94bd.1270486025.git.rth@twiddle.net> In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) Cc: qemu-devel@nongnu.org X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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~ 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;