From patchwork Mon Oct 22 20:17:46 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goffredo Baroncelli X-Patchwork-Id: 1627801 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id F3442DFB7A for ; Mon, 22 Oct 2012 20:17:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756177Ab2JVURo (ORCPT ); Mon, 22 Oct 2012 16:17:44 -0400 Received: from mail-bk0-f46.google.com ([209.85.214.46]:56671 "EHLO mail-bk0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932104Ab2JVURX (ORCPT ); Mon, 22 Oct 2012 16:17:23 -0400 Received: by mail-bk0-f46.google.com with SMTP id jk13so1245989bkc.19 for ; Mon, 22 Oct 2012 13:17:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=JOUoNp5dVFoujDOjWDwTLPC6DGSRc5qZqvR2L8CztEQ=; b=cSw0csAU3Y6K5jmzLbfESs5MnF6T65ev2QWPSM+n2o7JcpYBtyfnGMvLKbb6fzUzZy XXDyWBUQxuDcyVrnCOHV/UkuO/PXGpTy7cI7aE5+AZKzzrKfKeJP1+ChimYPPR15S0jL nsv5x1ogZN2XjELpPrLS3+o0k+BzFOgUUufHND6thWe75014lztak2QHaN6SSwWcetad TLRcjfjss7HipjtBDj8rW/EPSAAWWBktm3AcLT80kE01ywT5kXg09RUpsfL92BZungbQ g/vy0NKCLxXU4plkBQEiLAREqEwI8y0eqdo24/vvKAadNPyLVpopwWf90IrIpnURVK6i R3jA== Received: by 10.204.6.75 with SMTP id 11mr3050790bky.10.1350937043180; Mon, 22 Oct 2012 13:17:23 -0700 (PDT) Received: from venice..bhome (host103-133-static.242-95-b.business.telecomitalia.it. [95.242.133.103]) by mx.google.com with ESMTPS id x13sm4560199bkv.16.2012.10.22.13.17.22 (version=SSLv3 cipher=OTHER); Mon, 22 Oct 2012 13:17:22 -0700 (PDT) From: Goffredo Baroncelli To: linux-btrfs@vger.kernel.org Cc: Stefan Behrens , Wang Sheng-Hui , Goffredo Baroncelli Subject: [PATCH 3/5] parse_size(): check for invalid suffix Date: Mon, 22 Oct 2012 22:17:46 +0200 Message-Id: <1350937068-10080-4-git-send-email-kreijack@inwind.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1350937068-10080-1-git-send-email-kreijack@inwind.com> References: <1350937068-10080-1-git-send-email-kreijack@inwind.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goffredo Baroncelli Check that the suffix for the parse_size() input is of only one character. --- utils.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/utils.c b/utils.c index 732c782..de75309 100644 --- a/utils.c +++ b/utils.c @@ -1226,6 +1226,11 @@ u64 parse_size(char *s) char c; u64 mult = 1; + if( len <= 0 ){ + fprintf(stderr, "ERROR: size value is empty\n"); + exit(50); + } + if (!isdigit(s[len - 1])) { c = tolower(s[len - 1]); switch (c) { @@ -1242,6 +1247,13 @@ u64 parse_size(char *s) exit(1); } s[len - 1] = '\0'; + len--; + } + if( len > 0 && !isdigit(s[len - 1])) { + fprintf(stderr, "ERROR: Illegal size value contains " + "non-digit character %c in wrong position\n", + s[len-1]); + exit(51); } return strtoull(s, NULL, 0) * mult; }