* [PATCH] ext4: prefer strlcpy to strncpy
@ 2018-05-29 6:21 Nick Desaulniers
2018-05-30 1:59 ` Nick Desaulniers
2018-05-30 5:14 ` Theodore Y. Ts'o
0 siblings, 2 replies; 3+ messages in thread
From: Nick Desaulniers @ 2018-05-29 6:21 UTC (permalink / raw)
To: tytso, adilger.kernel; +Cc: Nick Desaulniers, linux-ext4, linux-kernel
Fixes a stringop-truncation warning from gcc-8.
Signed-off-by: Nick Desaulniers <nick.desaulniers@gmail.com>
---
fs/ext4/super.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index eb104e8..d47c85f 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -323,11 +323,11 @@ static void __save_error_info(struct super_block *sb, const char *func,
return;
es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
es->s_last_error_time = cpu_to_le32(get_seconds());
- strncpy(es->s_last_error_func, func, sizeof(es->s_last_error_func));
+ strlcpy(es->s_last_error_func, func, sizeof(es->s_last_error_func));
es->s_last_error_line = cpu_to_le32(line);
if (!es->s_first_error_time) {
es->s_first_error_time = es->s_last_error_time;
- strncpy(es->s_first_error_func, func,
+ strlcpy(es->s_first_error_func, func,
sizeof(es->s_first_error_func));
es->s_first_error_line = cpu_to_le32(line);
es->s_first_error_ino = es->s_last_error_ino;
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] ext4: prefer strlcpy to strncpy
2018-05-29 6:21 [PATCH] ext4: prefer strlcpy to strncpy Nick Desaulniers
@ 2018-05-30 1:59 ` Nick Desaulniers
2018-05-30 5:14 ` Theodore Y. Ts'o
1 sibling, 0 replies; 3+ messages in thread
From: Nick Desaulniers @ 2018-05-30 1:59 UTC (permalink / raw)
To: Theodore Ts'o, adilger.kernel
Cc: Nick Desaulniers, linux-ext4, Linux Kernel Mailing List, ebiggers
On Mon, May 28, 2018 at 11:21 PM, Nick Desaulniers
<nick.desaulniers@gmail.com> wrote:
> Fixes a stringop-truncation warning from gcc-8.
>
> Signed-off-by: Nick Desaulniers <nick.desaulniers@gmail.com>
> ---
> fs/ext4/super.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index eb104e8..d47c85f 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -323,11 +323,11 @@ static void __save_error_info(struct super_block *sb, const char *func,
> return;
> es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
> es->s_last_error_time = cpu_to_le32(get_seconds());
> - strncpy(es->s_last_error_func, func, sizeof(es->s_last_error_func));
> + strlcpy(es->s_last_error_func, func, sizeof(es->s_last_error_func));
> es->s_last_error_line = cpu_to_le32(line);
> if (!es->s_first_error_time) {
> es->s_first_error_time = es->s_last_error_time;
> - strncpy(es->s_first_error_func, func,
> + strlcpy(es->s_first_error_func, func,
> sizeof(es->s_first_error_func));
> es->s_first_error_line = cpu_to_le32(line);
> es->s_first_error_ino = es->s_last_error_ino;
> --
> 2.7.4
>
Eric points out this will leave the rest of dest uninitialized if size
is less than length of src.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ext4: prefer strlcpy to strncpy
2018-05-29 6:21 [PATCH] ext4: prefer strlcpy to strncpy Nick Desaulniers
2018-05-30 1:59 ` Nick Desaulniers
@ 2018-05-30 5:14 ` Theodore Y. Ts'o
1 sibling, 0 replies; 3+ messages in thread
From: Theodore Y. Ts'o @ 2018-05-30 5:14 UTC (permalink / raw)
To: Nick Desaulniers; +Cc: adilger.kernel, linux-ext4, linux-kernel
On Mon, May 28, 2018 at 11:21:53PM -0700, Nick Desaulniers wrote:
> Fixes a stringop-truncation warning from gcc-8.
>
> Signed-off-by: Nick Desaulniers <nick.desaulniers@gmail.com>
I'll note that the ext4 superblock fields are *not* guaranteed to be
NULL terminated. Code that references them must, and do, deal with
this appropriately. See for example:
https://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git/tree/lib/e2p/ls.c#n436
GCC-8 may whine about it, but the whine is, in fact, not correct.
It's making assumptions about all strings being null terminated, which
is often, but not always, the case.
Cheers,
- Ted
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-05-30 5:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-29 6:21 [PATCH] ext4: prefer strlcpy to strncpy Nick Desaulniers
2018-05-30 1:59 ` Nick Desaulniers
2018-05-30 5:14 ` Theodore Y. Ts'o
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.