Re: [PATCH] fs: fat: Prevent possible buffer overflow

2025-07-18 Thread Andrew Goodbody
On 17/07/2025 17:57, Martin Husemann wrote: On Thu, Jul 17, 2025 at 04:38:50PM +0100, Andrew Goodbody wrote: The original use of strcpy suggests that the string must be \0 terminated. I will admit that I do not know the code well, is dir->itr.name guaranteed to be a known fixed size? You are r

Re: [PATCH] fs: fat: Prevent possible buffer overflow

2025-07-17 Thread Martin Husemann
On Thu, Jul 17, 2025 at 04:38:50PM +0100, Andrew Goodbody wrote: > The original use of strcpy suggests that the string must be \0 terminated. I > will admit that I do not know the code well, is dir->itr.name guaranteed to > be a known fixed size? You are right, the iterator's name pointer always p

Re: [PATCH] fs: fat: Prevent possible buffer overflow

2025-07-17 Thread Andrew Goodbody
On 17/07/2025 15:58, Martin Husemann wrote: On Thu, Jul 17, 2025 at 03:54:37PM +0100, Andrew Goodbody wrote: memset(dent, 0, sizeof(*dent)); - strcpy(dent->name, dir->itr.name); + strlcpy(dent->name, dir->itr.name, FS_DIRENT_NAME_LEN); Shouldn't that be strncpy() instead? Usi

Re: [PATCH] fs: fat: Prevent possible buffer overflow

2025-07-17 Thread Martin Husemann
On Thu, Jul 17, 2025 at 03:54:37PM +0100, Andrew Goodbody wrote: > > memset(dent, 0, sizeof(*dent)); > - strcpy(dent->name, dir->itr.name); > + strlcpy(dent->name, dir->itr.name, FS_DIRENT_NAME_LEN); Shouldn't that be strncpy() instead? Using strlcpy() for fixed size records where

[PATCH] fs: fat: Prevent possible buffer overflow

2025-07-17 Thread Andrew Goodbody
Instead of strcpy which is unbounded use strlcpy to ensure that the receiving buffer cannot be overflowed. This issue found by Smatch. Signed-off-by: Andrew Goodbody --- fs/fat/fat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/fat/fat.c b/fs/fat/fat.c index 89f2acbba1