linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Jérémy Lefaure" <jeremy.lefaure@lse.epita.fr>
To: Andy Shevchenko <andy.shevchenko@gmail.com>,
	David Howells <dhowells@redhat.com>
Cc: linux-doc@vger.kernel.org, "Jonathan Corbet" <corbet@lwn.net>,
	linux-cachefs@redhat.com, linux-kernel@vger.kernel.org,
	"Jérémy Lefaure" <jeremy.lefaure@lse.epita.fr>
Subject: [PATCH v2] FS-Cache: fix buffer size for decimal value of special cookie type
Date: Wed, 26 Apr 2017 20:31:38 -0400	[thread overview]
Message-ID: <20170427003138.6977-1-jeremy.lefaure@lse.epita.fr> (raw)
In-Reply-To: <20170419203819.21951-1-jeremy.lefaure@lse.epita.fr>

When building object-list.o, gcc (version 7) raises a warning on the
sprintf call in fscache_objlist_show:

  CC      fs/fscache/object-list.o
fs/fscache/object-list.c: In function ‘fscache_objlist_show’:
fs/fscache/object-list.c:265:19: warning: ‘sprintf’ may write a
terminating nul past the end of the destination [-Wformat-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
    sprintf(_type, "%02u", cookie->def->type);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Moreover, the documentation says that value for special cookies is a
hexadecimal value (see Documentation/filesystems/caching/fscache.txt).

Increasing the buffer size to use a decimal value fixes the problem
without any effect on userland tools. Also, this patch updates the
documentation.

Signed-off-by: Jérémy Lefaure <jeremy.lefaure@lse.epita.fr>
---
v2:
_ keep decimal value
_ fix _type buffer size
_ fix documentation

I didn't have the time to test this patch yet but everything should be fine.


 Documentation/filesystems/caching/fscache.txt |  2 +-
 fs/fscache/object-list.c                      | 10 +++++-----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/Documentation/filesystems/caching/fscache.txt b/Documentation/filesystems/caching/fscache.txt
index 50f0a5757f48..9c3df61b3c16 100644
--- a/Documentation/filesystems/caching/fscache.txt
+++ b/Documentation/filesystems/caching/fscache.txt
@@ -374,7 +374,7 @@ and the second set of columns describe the object's cookie, if present:
 	COLUMN		DESCRIPTION
 	===============	=======================================================
 	NETFS_COOKIE_DEF Name of netfs cookie definition
-	TY		Cookie type (IX - index, DT - data, hex - special)
+	TY		Cookie type (IX - index, DT - data, decimal - special)
 	FL		Cookie flags
 	NETFS_DATA	Netfs private data stored in the cookie
 	OBJECT_KEY	Object key	} 1 column, with separating comma
diff --git a/fs/fscache/object-list.c b/fs/fscache/object-list.c
index 67f940892ef8..3452d7dbf1e1 100644
--- a/fs/fscache/object-list.c
+++ b/fs/fscache/object-list.c
@@ -169,7 +169,7 @@ static int fscache_objlist_show(struct seq_file *m, void *v)
 	struct fscache_object *obj = v;
 	struct fscache_cookie *cookie;
 	unsigned long config = data->config;
-	char _type[3], *type;
+	char _type[4], *type;
 	u8 *buf = data->buf, *p;
 
 	if ((unsigned long) v == 1) {
@@ -194,7 +194,7 @@ static int fscache_objlist_show(struct seq_file *m, void *v)
 	if ((unsigned long) v == 2) {
 		seq_puts(m, "======== ======== ==== ===== === === === == ====="
 			 " == == == ="
-			 " | ================ == == ================");
+			 " | ================ === == ================");
 		if (config & (FSCACHE_OBJLIST_CONFIG_KEY |
 			      FSCACHE_OBJLIST_CONFIG_AUX))
 			seq_puts(m, " ================");
@@ -256,13 +256,13 @@ static int fscache_objlist_show(struct seq_file *m, void *v)
 
 		switch (cookie->def->type) {
 		case 0:
-			type = "IX";
+			type = " IX";
 			break;
 		case 1:
-			type = "DT";
+			type = " DT";
 			break;
 		default:
-			sprintf(_type, "%02u", cookie->def->type);
+			sprintf(_type, "%03u", cookie->def->type);
 			type = _type;
 			break;
 		}
-- 
2.12.2

  parent reply	other threads:[~2017-04-27  0:31 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-19 20:38 [PATCH] FS-Cache: print hexadecimal value for special cookies type Jérémy Lefaure
2017-04-21 19:41 ` Andy Shevchenko
2017-04-21 23:09   ` Jérémy Lefaure
2017-04-24 21:47     ` Andy Shevchenko
2017-04-25 21:37       ` Jérémy Lefaure
2017-04-25 22:04         ` Andy Shevchenko
2017-04-27  0:31 ` Jérémy Lefaure [this message]
2017-04-27 15:03 ` David Howells
2017-04-27 15:11   ` Jérémy Lefaure
2017-04-27 15:41   ` David Howells
2017-05-28  0:31   ` Jérémy Lefaure

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170427003138.6977-1-jeremy.lefaure@lse.epita.fr \
    --to=jeremy.lefaure@lse.epita.fr \
    --cc=andy.shevchenko@gmail.com \
    --cc=corbet@lwn.net \
    --cc=dhowells@redhat.com \
    --cc=linux-cachefs@redhat.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).