From patchwork Wed Feb 8 21:26:22 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 140264 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (unknown [IPv6:2001:4978:20e::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 336A7B6F13 for ; Thu, 9 Feb 2012 08:30:07 +1100 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1RvF4h-0000Rs-5P; Wed, 08 Feb 2012 21:29:11 +0000 Received: from mail-pz0-f49.google.com ([209.85.210.49]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1RvF4e-0000LS-6w for linux-mtd@lists.infradead.org; Wed, 08 Feb 2012 21:29:08 +0000 Received: by mail-pz0-f49.google.com with SMTP id p5so1010948dak.36 for ; Wed, 08 Feb 2012 13:29:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=2MhF6wMP2W3yS9hMymDhihbPrTobewaNvTxymUn3ZkE=; b=WsPFI2kVbGUX+BAcCwGMkc//d3AX3q8yIkmCPWvQLA3Hi7PMfrzP/1//+7OMveDAHO 6uMgWDBFBgHP3n3lp9rVKWQnbQhSwnG2jNyVjRGil8JdAizjnDmSQUpqVIgM7L8uwM/k WLr4cL8ddCaGd/7ys+gRBEmwPYorUwg0wA9lI= Received: by 10.68.238.229 with SMTP id vn5mr72845025pbc.39.1328736547940; Wed, 08 Feb 2012 13:29:07 -0800 (PST) Received: from localhost.localdomain (5520-maca-inet1-outside.broadcom.com. [216.31.211.11]) by mx.google.com with ESMTPS id i10sm1165979pbg.10.2012.02.08.13.29.06 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 08 Feb 2012 13:29:07 -0800 (PST) From: Brian Norris To: Artem Bityutskiy Subject: [PATCH 3/3] libmtd: fix segmentation fault on lib->mtd Date: Wed, 8 Feb 2012 13:26:22 -0800 Message-Id: <1328736382-5798-3-git-send-email-computersforpeace@gmail.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1328736382-5798-1-git-send-email-computersforpeace@gmail.com> References: <1328736382-5798-1-git-send-email-computersforpeace@gmail.com> X-Spam-Note: CRM114 invocation failed X-Spam-Score: -1.4 (-) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-1.4 points) pts rule name description ---- ---------------------- -------------------------------------------------- 1.3 RCVD_IN_BL_SPAMCOP_NET RBL: Received via a relay in bl.spamcop.net [Blocked - see ] -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.210.49 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (computersforpeace[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: Brian Foster , Brian Norris , linux-mtd@lists.infradead.org X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Legacy systems do not initialize lib->mtd, so we shouldn't perform strlen(lib->mtd); this produces a segmentation fault. As this code isn't used in the legacy codepath, we can just move it down to an 'else' branch. Signed-off-by: Brian Norris --- lib/libmtd.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/libmtd.c b/lib/libmtd.c index 2bb4e57..fb4586c 100644 --- a/lib/libmtd.c +++ b/lib/libmtd.c @@ -644,13 +644,15 @@ void libmtd_close(libmtd_t desc) int mtd_dev_present(libmtd_t desc, int mtd_num) { struct stat st; struct libmtd *lib = (struct libmtd *)desc; - char file[strlen(lib->mtd) + 10]; if (!lib->sysfs_supported) return legacy_dev_present(mtd_num); + else { + char file[strlen(lib->mtd) + 10]; - sprintf(file, lib->mtd, mtd_num); - return !stat(file, &st); + sprintf(file, lib->mtd, mtd_num); + return !stat(file, &st); + } } int mtd_get_info(libmtd_t desc, struct mtd_info *info)