From patchwork Wed Jan 11 16:35:18 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artem Bityutskiy X-Patchwork-Id: 135425 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3BC0CB6EF3 for ; Thu, 12 Jan 2012 03:34:11 +1100 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1Rl16p-0003kz-T5; Wed, 11 Jan 2012 16:33:07 +0000 Received: from mga01.intel.com ([192.55.52.88]) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1Rl16k-0003iD-Hp for linux-mtd@lists.infradead.org; Wed, 11 Jan 2012 16:33:04 +0000 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP; 11 Jan 2012 08:32:54 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.71,315,1320652800"; d="scan'208";a="111141126" Received: from sauron.fi.intel.com ([10.237.72.160]) by fmsmga002.fm.intel.com with ESMTP; 11 Jan 2012 08:32:53 -0800 From: Artem Bityutskiy To: linux-mtd@lists.infradead.org Subject: [PATCH 2/2] UBIFS: use snprintf instead of sprintf when printing keys Date: Wed, 11 Jan 2012 18:35:18 +0200 Message-Id: <1326299718-30697-2-git-send-email-dedekind1@gmail.com> X-Mailer: git-send-email 1.7.7.5 In-Reply-To: <1326299718-30697-1-git-send-email-dedekind1@gmail.com> References: <1326299718-30697-1-git-send-email-dedekind1@gmail.com> X-Spam-Note: CRM114 invocation failed X-Spam-Score: -5.0 (-----) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-5.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (dedekind1[at]gmail.com) -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [192.55.52.88 listed in list.dnswl.org] 0.0 DKIM_ADSP_CUSTOM_MED No valid author signature, adsp_override is CUSTOM_MED 0.8 SPF_NEUTRAL SPF: sender does not match SPF record (neutral) 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit (dedekind1[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.9 NML_ADSP_CUSTOM_MED ADSP custom_med hit, and not from a mailing list 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 From: Artem Bityutskiy Switch to 'snprintf()' which is more secure and reliable. This is also a preparation to the subsequent key printing fixes. Signed-off-by: Artem Bityutskiy --- fs/ubifs/debug.c | 38 ++++++++++++++++++++------------------ 1 files changed, 20 insertions(+), 18 deletions(-) diff --git a/fs/ubifs/debug.c b/fs/ubifs/debug.c index b09ba2d..6ae9fdc 100644 --- a/fs/ubifs/debug.c +++ b/fs/ubifs/debug.c @@ -103,8 +103,8 @@ static const char *get_dent_type(int type) } } -static void sprintf_key(const struct ubifs_info *c, const union ubifs_key *key, - char *buffer) +static void snprintf_key(const struct ubifs_info *c, const union ubifs_key *key, + char *buffer, int len) { char *p = buffer; int type = key_type(c, key); @@ -112,44 +112,46 @@ static void sprintf_key(const struct ubifs_info *c, const union ubifs_key *key, if (c->key_fmt == UBIFS_SIMPLE_KEY_FMT) { switch (type) { case UBIFS_INO_KEY: - sprintf(p, "(%lu, %s)", (unsigned long)key_inum(c, key), - get_key_type(type)); + len -= snprintf(p, len, "(%lu, %s)", + (unsigned long)key_inum(c, key), + get_key_type(type)); break; case UBIFS_DENT_KEY: case UBIFS_XENT_KEY: - sprintf(p, "(%lu, %s, %#08x)", - (unsigned long)key_inum(c, key), - get_key_type(type), key_hash(c, key)); + len -= snprintf(p, len, "(%lu, %s, %#08x)", + (unsigned long)key_inum(c, key), + get_key_type(type), key_hash(c, key)); break; case UBIFS_DATA_KEY: - sprintf(p, "(%lu, %s, %u)", - (unsigned long)key_inum(c, key), - get_key_type(type), key_block(c, key)); + len -= snprintf(p, len, "(%lu, %s, %u)", + (unsigned long)key_inum(c, key), + get_key_type(type), key_block(c, key)); break; case UBIFS_TRUN_KEY: - sprintf(p, "(%lu, %s)", - (unsigned long)key_inum(c, key), - get_key_type(type)); + len -= snprintf(p, len, "(%lu, %s)", + (unsigned long)key_inum(c, key), + get_key_type(type)); break; default: - sprintf(p, "(bad key type: %#08x, %#08x)", - key->u32[0], key->u32[1]); + len -= snprintf(p, len, "(bad key type: %#08x, %#08x)", + key->u32[0], key->u32[1]); } } else - sprintf(p, "bad key format %d", c->key_fmt); + len -= snprintf(p, len, "bad key format %d", c->key_fmt); + ubifs_assert(len > 0); } const char *dbg_key_str0(const struct ubifs_info *c, const union ubifs_key *key) { /* dbg_lock must be held */ - sprintf_key(c, key, dbg_key_buf0); + snprintf_key(c, key, dbg_key_buf0, sizeof(dbg_key_buf0) - 1); return dbg_key_buf0; } const char *dbg_key_str1(const struct ubifs_info *c, const union ubifs_key *key) { /* dbg_lock must be held */ - sprintf_key(c, key, dbg_key_buf1); + snprintf_key(c, key, dbg_key_buf1, sizeof(dbg_key_buf1) - 1); return dbg_key_buf1; }