Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932277AbdGNMOn (ORCPT ); Fri, 14 Jul 2017 08:14:43 -0400 Received: from mout.kundenserver.de ([212.227.17.24]:62281 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754032AbdGNMOk (ORCPT ); Fri, 14 Jul 2017 08:14:40 -0400 From: Arnd Bergmann To: linux-kernel@vger.kernel.org, David Howells Cc: Greg Kroah-Hartman , Linus Torvalds , Guenter Roeck , akpm@linux-foundation.org, netdev@vger.kernel.org, "David S . Miller" , "James E . J . Bottomley" , "Martin K . Petersen" , linux-scsi@vger.kernel.org, x86@kernel.org, Arnd Bergmann , James Morris , linux-cachefs@redhat.com Subject: [PATCH 21/22] fscache: fix fscache_objlist_show format processing Date: Fri, 14 Jul 2017 14:07:13 +0200 Message-Id: <20170714120720.906842-22-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170714120720.906842-1-arnd@arndb.de> References: <20170714120720.906842-1-arnd@arndb.de> X-Provags-ID: V03:K0:YFZAzTJTor7ESab3x/y3CyF9Q0zEzuiRH9Ykov65kfR3TBb9zUd vVqKVFgW1jv4QCOOlXlH6EZSRpLhZHHhMd7LEGHfLTrbO2E+moOVlnsDqK5NKhsU9hE8km1 8uiMAmVC2j2i8d9eN4PgLGZxDKIo0jkoMDedxvX+Et6LE7pJygNR3ZyOqZTkq1mXpmKk6q6 NCihx9jYG+hBLkcxrN2BQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:mA5l/ZB/hlo=:ufIqD9IA8RqJFDyMte9BQf 3EWLpdMT57DBQhD7uqriIn3QNIpkNIRLlBbvCggp6NmLUKT87ENkFF107WPs365c5QmJgEmh8 zUcjjqm42upAPXhZGQhsNLa80SY+S99hR9h6Q14rCtLkSqZTKJfRhHE4UyvZQJG8smt847GAE axni8LB2rfMH3IEb0D2J74i5whbcblgtwzamVx700yazrC7fxpI+kkaj9vLamRikqSo6kZ3jS Zk1K5SV0g20SKH2awp+EKcABof4T22M58Qu+EnzWgiqTEnxHky61n796jp91hfBA5sj6CGH7y 9Q+kAwv81XB5pwNs/MnyetLSVJFFpIpjOCwHtm1BLrWcCezSRE4hk2ngUsVbJV6D9MVTv+TFp NW7Oa1JlfHYkCnTyZmJlVfRrYzYMTFHpOtuPzWUd5NFmFc+Wo/+eJCZtrrlmrXMDUQLPQ6hVr nluYs/iJ+WEsgdU9DDjn9oMNvCB1HKU0vSMcXoTJhCvFKRAf+Q2/5I3rkLv43whDaimI3qL03 2VjQs63eEpYIMTAueEK1g8nZLEcRrwvRMlUho/O4Avw3BDEI4hTZrxOEci/Px77dODC9drwR0 jOpIHq6jGRkwz85bFKGyg5IQcx8tjZ1ZRAo00DE+9snEg9SCCa1MaI8BUMKRVrHbTB8phdCoW k6fukTwOX5//tKUkLhWd6QaE7/1W1ifnfPDgAGSP8h7+y5yDFsH/kTLeJ/Iq9xImIFtAHxl8b gZYuksucjUt4slRZ2n3qUSPoFAdnlgoi6/lHWw== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1271 Lines: 35 gcc points out a minor bug in the handling of unknown cookie types, which could result in a string overflow when the integer is copied into a 3-byte string: fs/fscache/object-list.c: In function 'fscache_objlist_show': fs/fscache/object-list.c:265:19: error: 'sprintf' may write a terminating nul past the end of the destination [-Werror=format-overflow=] sprintf(_type, "%02u", cookie->def->type); ^~~~~~ fs/fscache/object-list.c:265:4: note: 'sprintf' output between 3 and 4 bytes into a destination of size 3 This is currently harmless as no code sets a type other than 0 or 1, but it makes sense to use snprintf() here to avoid overflowing the array if that changes. Signed-off-by: Arnd Bergmann --- fs/fscache/object-list.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/fscache/object-list.c b/fs/fscache/object-list.c index 67f940892ef8..b5ab06fabc60 100644 --- a/fs/fscache/object-list.c +++ b/fs/fscache/object-list.c @@ -262,7 +262,8 @@ static int fscache_objlist_show(struct seq_file *m, void *v) type = "DT"; break; default: - sprintf(_type, "%02u", cookie->def->type); + snprintf(_type, sizeof(_type), "%02u", + cookie->def->type); type = _type; break; } -- 2.9.0