* [PATCH] ext4: Fix a test in ext4_decode_error()
@ 2023-09-09 16:07 Christophe JAILLET
2023-09-12 1:49 ` Theodore Ts'o
0 siblings, 1 reply; 2+ messages in thread
From: Christophe JAILLET @ 2023-09-09 16:07 UTC (permalink / raw)
To: Theodore Ts'o, Andreas Dilger, Dave Kleikamp, Andrew Morton
Cc: linux-kernel, kernel-janitors, Christophe JAILLET, linux-ext4
The doc of snprintf() states that "If the return is greater than or equal
to @size, the resulting string is truncated".
So in order to "Check for truncated error codes...", we must check that the
returned value is < 16.
Fixes: ac27a0ec112a ("[PATCH] ext4: initial copy of files from ext3")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
fs/ext4/super.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 38217422f938..f58fc7cc6f81 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -941,7 +941,7 @@ const char *ext4_decode_error(struct super_block *sb, int errno,
* NULL. */
if (nbuf) {
/* Check for truncated error codes... */
- if (snprintf(nbuf, 16, "error %d", -errno) >= 0)
+ if (snprintf(nbuf, 16, "error %d", -errno) < 16)
errstr = nbuf;
}
break;
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] ext4: Fix a test in ext4_decode_error()
2023-09-09 16:07 [PATCH] ext4: Fix a test in ext4_decode_error() Christophe JAILLET
@ 2023-09-12 1:49 ` Theodore Ts'o
0 siblings, 0 replies; 2+ messages in thread
From: Theodore Ts'o @ 2023-09-12 1:49 UTC (permalink / raw)
To: Christophe JAILLET
Cc: Andreas Dilger, Dave Kleikamp, Andrew Morton, linux-kernel,
kernel-janitors, linux-ext4
On Sat, Sep 09, 2023 at 06:07:02PM +0200, Christophe JAILLET wrote:
> The doc of snprintf() states that "If the return is greater than or equal
> to @size, the resulting string is truncated".
>
> So in order to "Check for truncated error codes...", we must check that the
> returned value is < 16.
>
> Fixes: ac27a0ec112a ("[PATCH] ext4: initial copy of files from ext3")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
This patch is not needed. It's fine if snprintf truncates the string,
since it will still be null terminated. This was checking for the
case where snprintf() returns an error, and the comment was
misleading.
Looking that the current implementation of the kernel snprintf, it
will never return a negative number, and nbuf is always passed in from
the callers, so it could be changed to
snprintf(nbuf, 16, "error %d", -errno);
errstr = nbuf;
But what is currently there is certainly valid.
- Ted
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-09-12 3:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-09 16:07 [PATCH] ext4: Fix a test in ext4_decode_error() Christophe JAILLET
2023-09-12 1:49 ` Theodore Ts'o
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).