* [PATCH] befs: use strlcpy()
@ 2005-10-30 1:18 Alexey Dobriyan
2005-10-30 10:38 ` Andreas Schwab
0 siblings, 1 reply; 2+ messages in thread
From: Alexey Dobriyan @ 2005-10-30 1:18 UTC (permalink / raw)
To: Andrew Morton; +Cc: Sergey S. Kostyliov, linux-kernel
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---
Looks like second strncpy() can fill symlink buffer without
NUL-termination which would cause bad things later, though I
may be wrong.
fs/befs/btree.c | 3 +--
fs/befs/linuxvfs.c | 4 ++--
2 files changed, 3 insertions(+), 4 deletions(-)
--- a/fs/befs/btree.c
+++ b/fs/befs/btree.c
@@ -503,10 +503,9 @@ befs_btree_read(struct super_block *sb,
goto error_alloc;
};
- strncpy(keybuf, keystart, keylen);
+ strlcpy(keybuf, keystart, keylen);
*value = fs64_to_cpu(sb, valarray[cur_key]);
*keysize = keylen;
- keybuf[keylen] = '\0';
befs_debug(sb, "Read [%Lu,%d]: Key \"%.*s\", Value %Lu", node_off,
cur_key, keylen, keybuf, *value);
--- linux-vanilla/fs/befs/linuxvfs.c
+++ linux-strlcpy/fs/befs/linuxvfs.c
@@ -381,8 +381,8 @@ befs_read_inode(struct inode *inode)
if (S_ISLNK(inode->i_mode) && !(befs_ino->i_flags & BEFS_LONG_SYMLINK)){
inode->i_size = 0;
inode->i_blocks = befs_sb->block_size / VFS_BLOCK_SIZE;
- strncpy(befs_ino->i_data.symlink, raw_inode->data.symlink,
- BEFS_SYMLINK_LEN);
+ strlcpy(befs_ino->i_data.symlink, raw_inode->data.symlink,
+ sizeof(befs_ino->i_data.symlink));
} else {
int num_blks;
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] befs: use strlcpy()
2005-10-30 1:18 [PATCH] befs: use strlcpy() Alexey Dobriyan
@ 2005-10-30 10:38 ` Andreas Schwab
0 siblings, 0 replies; 2+ messages in thread
From: Andreas Schwab @ 2005-10-30 10:38 UTC (permalink / raw)
To: Alexey Dobriyan; +Cc: Andrew Morton, Sergey S. Kostyliov, linux-kernel
Alexey Dobriyan <adobriyan@gmail.com> writes:
> --- a/fs/befs/btree.c
> +++ b/fs/befs/btree.c
> @@ -503,10 +503,9 @@ befs_btree_read(struct super_block *sb,
> goto error_alloc;
> };
>
> - strncpy(keybuf, keystart, keylen);
> + strlcpy(keybuf, keystart, keylen);
> *value = fs64_to_cpu(sb, valarray[cur_key]);
> *keysize = keylen;
> - keybuf[keylen] = '\0';
You are now cutting off the last character of the string. keylen is the
exact size of the string to be copied, _not_ the size of the buffer (which
is bufsize and guaranteed to be big enough at this point).
Andreas.
--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2005-10-30 10:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-10-30 1:18 [PATCH] befs: use strlcpy() Alexey Dobriyan
2005-10-30 10:38 ` Andreas Schwab
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®