From patchwork Sat Nov 3 00:27:29 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 196788 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id B4F7F2C00DB for ; Sat, 3 Nov 2012 11:30:25 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 57DA74A233; Sat, 3 Nov 2012 01:29:31 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6CSDZNKsHzMG; Sat, 3 Nov 2012 01:29:31 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A5DE84A542; Sat, 3 Nov 2012 01:28:22 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 839634A528 for ; Sat, 3 Nov 2012 01:28:16 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8Whz30UHKTgA for ; Sat, 3 Nov 2012 01:28:14 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-vc0-f202.google.com (mail-vc0-f202.google.com [209.85.220.202]) by theia.denx.de (Postfix) with ESMTPS id 6ED624A4F4 for ; Sat, 3 Nov 2012 01:28:04 +0100 (CET) Received: by mail-vc0-f202.google.com with SMTP id fy27so486107vcb.3 for ; Fri, 02 Nov 2012 17:28:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=7BESuIen8Vi3iyzNJFiLfJBOWtI/HM2wG74CWgsRD40=; b=mXr3HDKW89Ef4LLOEnhkenx7gWXBebzy15sRBOLcja1JK+NNacazbgetuS7ykWsnE8 QwZjS0lInLBWcgRxykfPFMXWSB1wBWwyu9AFw375cjcpObdru4gjR53H0abNiFZY79DB nghmgIzFinSYnNa1+GE61f7fX6gIjtsZaROs+CddOgtmbXGl7drzQlpco1wCVY7Au94r fyocEQpP6NUJYgFak6PGDhdH1ZOpY1ZFsiXPkQ6G2cMl7dP3HzIdQ8W5pdJpdk70sMPR LS9Pp9iWvDdBOzepJMBxFyo/edHAQUo9pfv4DQqhkluj0KN0Tdf30NDG3Eaw6dDFZmht +5hA== Received: by 10.236.134.16 with SMTP id r16mr2101751yhi.48.1351902483524; Fri, 02 Nov 2012 17:28:03 -0700 (PDT) Received: from wpzn3.hot.corp.google.com (216-239-44-65.google.com [216.239.44.65]) by gmr-mx.google.com with ESMTPS id r10si392808ann.1.2012.11.02.17.28.03 (version=TLSv1/SSLv3 cipher=AES128-SHA); Fri, 02 Nov 2012 17:28:03 -0700 (PDT) Received: from kaka.mtv.corp.google.com (kaka.mtv.corp.google.com [172.22.73.79]) by wpzn3.hot.corp.google.com (Postfix) with ESMTP id 4BD7B100048; Fri, 2 Nov 2012 17:28:03 -0700 (PDT) Received: by kaka.mtv.corp.google.com (Postfix, from userid 121222) id C9A8B1604FE; Fri, 2 Nov 2012 17:28:02 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Fri, 2 Nov 2012 17:27:29 -0700 Message-Id: <1351902453-27956-14-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <1351902453-27956-1-git-send-email-sjg@chromium.org> References: <1351902453-27956-1-git-send-email-sjg@chromium.org> X-Gm-Message-State: ALoCoQnh/U/jJNVPx9QCEEUNZ0xmHWSiQRndpAfKHS/VwFe6eKVumUaQUPK80/eqnjnhY5fQrIW0qu20oNGfof08lfWAZaJqVETrrHlqeFhMs5DdiwCaQQDU3j9XrF4WZvBGkPTpjpPsb8Of9AYl7YmiLadDx77S/Odw8fcBzZpL3c9A3jyF2xhj4/bkSWJnvJeJjD+0cB4l Cc: Tom Rini , Andy Fleming , Taylor Hutt Subject: [U-Boot] [PATCH 13/17] mmc: Fix incorrect handling of 'read' & 'write' commands X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de From: Taylor Hutt If a malformed 'read' or 'write' command is issued, the Sandbox U-Boot can crash because the command-handling code does no error checking on the number of provided arguments. This change makes the mmc 'erase', 'read' and 'write' commands only function if the proper number of arguments are supplied. Also puts the else assignment at the beginning fo the if() statement to shortens the generated code. This removes an unnecessary jump from the generated code. BRANCH=none Signed-off-by: Taylor Hutt Signed-off-by: Simon Glass --- common/cmd_mmc.c | 9 ++++----- 1 files changed, 4 insertions(+), 5 deletions(-) diff --git a/common/cmd_mmc.c b/common/cmd_mmc.c index 79a1088..735947b 100644 --- a/common/cmd_mmc.c +++ b/common/cmd_mmc.c @@ -250,14 +250,13 @@ int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return 0; } - if (strcmp(argv[1], "read") == 0) + state = MMC_INVALID; + if (argc == 5 && strcmp(argv[1], "read") == 0) state = MMC_READ; - else if (strcmp(argv[1], "write") == 0) + else if (argc == 5 && strcmp(argv[1], "write") == 0) state = MMC_WRITE; - else if (strcmp(argv[1], "erase") == 0) + else if (argc == 4 && strcmp(argv[1], "erase") == 0) state = MMC_ERASE; - else - state = MMC_INVALID; if (state != MMC_INVALID) { struct mmc *mmc = find_mmc_device(curr_device);