From patchwork Wed Nov 5 12:53:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leif Lindholm X-Patchwork-Id: 40185 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CC00A240A6 for ; Wed, 5 Nov 2014 12:53:54 +0000 (UTC) Received: by mail-wi0-f197.google.com with SMTP id ex7sf830324wid.4 for ; Wed, 05 Nov 2014 04:53:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:date:from:to:subject:message-id :mime-version:user-agent:precedence:reply-to:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list:content-disposition :content-type:content-transfer-encoding; bh=P2qUfC5/UQNiJFQolPvjtrMqsFhLJxNBTsa8X3/CCjo=; b=NpFyyOMDWHOYKxNVEHRsG77WEp7/LraRL0Ns4nd25iv23c9aJpyrYdSaamBhlrWpYy V6/FO3unP65CHM6f+7nc4gC6Rv1zIgVwCECUQ7Lop4dtNyNfrznj71LWP7TmZrze5OCT qDnh84ERGSkwXEQynFEUmXzbAlr9Hz5mVYktKKfm7F1ThfHIUvrWzMytXQ9KiqBu400T FFmAjwrcifKWM4Wgjmqk36y5wTk8prwS+v5MQgH8Q0dUn+gAJQSOyLMawwn/B1/3e3kz IK+XV4AyAJ9g+hIFXQP+rgvR0DFDb53NBaMPhG9Q7KXrE7pc71ClfSPfxRZVpZj6qrL3 BYkw== X-Gm-Message-State: ALoCoQlyQn6fXN5DxLYm1OEriBHwo5UPtzePEez+bK2Gj6YTAUB2664EamatPl4ruLfrZ7p3G8Gc X-Received: by 10.112.146.104 with SMTP id tb8mr30966lbb.22.1415192030776; Wed, 05 Nov 2014 04:53:50 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.99 with SMTP id r3ls970607lar.73.gmail; Wed, 05 Nov 2014 04:53:50 -0800 (PST) X-Received: by 10.152.22.194 with SMTP id g2mr67474781laf.33.1415192030305; Wed, 05 Nov 2014 04:53:50 -0800 (PST) Received: from mail-lb0-f174.google.com (mail-lb0-f174.google.com. [209.85.217.174]) by mx.google.com with ESMTPS id ld12si5897765lac.105.2014.11.05.04.53.50 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 05 Nov 2014 04:53:50 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) client-ip=209.85.217.174; Received: by mail-lb0-f174.google.com with SMTP id p9so586099lbv.33 for ; Wed, 05 Nov 2014 04:53:50 -0800 (PST) X-Received: by 10.112.77.74 with SMTP id q10mr66795717lbw.66.1415192030190; Wed, 05 Nov 2014 04:53:50 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.184.201 with SMTP id ew9csp276250lbc; Wed, 5 Nov 2014 04:53:49 -0800 (PST) X-Received: by 10.224.167.132 with SMTP id q4mr84288690qay.48.1415192028881; Wed, 05 Nov 2014 04:53:48 -0800 (PST) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id b11si6073615qgb.101.2014.11.05.04.53.48 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 05 Nov 2014 04:53:48 -0800 (PST) Received-SPF: pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:46106 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xm05s-0001TQ-5k for patch@linaro.org; Wed, 05 Nov 2014 07:53:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43853) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xm05k-0001TF-Q1 for grub-devel@gnu.org; Wed, 05 Nov 2014 07:53:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xm05f-0005lb-Ut for grub-devel@gnu.org; Wed, 05 Nov 2014 07:53:40 -0500 Received: from mail-wg0-f45.google.com ([74.125.82.45]:42045) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xm05f-0005lU-Pm for grub-devel@gnu.org; Wed, 05 Nov 2014 07:53:35 -0500 Received: by mail-wg0-f45.google.com with SMTP id x12so838874wgg.4 for ; Wed, 05 Nov 2014 04:53:34 -0800 (PST) X-Received: by 10.180.102.65 with SMTP id fm1mr5760940wib.16.1415192014626; Wed, 05 Nov 2014 04:53:34 -0800 (PST) Received: from bivouac.eciton.net (bivouac.eciton.net. [2a00:1098:0:86:1000:23:0:2]) by mx.google.com with ESMTPSA id h8sm3965900wjs.43.2014.11.05.04.53.33 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 05 Nov 2014 04:53:33 -0800 (PST) Date: Wed, 5 Nov 2014 12:53:31 +0000 From: Leif Lindholm To: grub-devel@gnu.org Subject: [PATCH] efi: check *path non-null before grub_strrchr Message-ID: <20141105125331.GB22224@bivouac.eciton.net> MIME-Version: 1.0 User-Agent: Mutt/1.5.21 (2010-09-15) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 74.125.82.45 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: grub-devel-bounces+patch=linaro.org@gnu.org Sender: grub-devel-bounces+patch=linaro.org@gnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: leif.lindholm@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Content-Disposition: inline The EFI version of grub_machine_get_bootlocation crops the boot image name back to the last / in order to get a directory path. However, it does not check that *name is actually set before calling grub_strrchr to do this, and neither does grub_strrchr before dereferencing a NULL pointer. Parent function, grub_set_prefix_and_root, does check the pointer before using. Signed-off-by: Leif Lindholm --- grub-core/kern/efi/init.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) void -- 1.7.10.4 diff --git a/grub-core/kern/efi/init.c b/grub-core/kern/efi/init.c index 942ab02..e9c85de 100644 --- a/grub-core/kern/efi/init.c +++ b/grub-core/kern/efi/init.c @@ -63,10 +63,13 @@ grub_machine_get_bootlocation (char **device, char **path) if (!*device && grub_efi_net_config) grub_efi_net_config (image->device_handle, device, path); - /* Get the directory. */ - p = grub_strrchr (*path, '/'); - if (p) - *p = '\0'; + if (*path) + { + /* Get the directory. */ + p = grub_strrchr (*path, '/'); + if (p) + *p = '\0'; + } }