Skip to content

Commit

Permalink
Btrfs: avoid buffer overrun in btrfs_printk
Browse files Browse the repository at this point in the history
The buffer read-overrun would be triggered by a printk format
starting with <N>, where N is a single digit.  NUL-terminate
after strncpy.  Use memcpy, not strncpy, since we know the
string we're copying fits in the destination buffer and
contains no NUL byte.

Signed-off-by: Jim Meyering <meyering@redhat.com>
  • Loading branch information
Jim Meyering authored and Josef Bacik committed May 30, 2012
1 parent 2eec6c8 commit f07c9a7
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion fs/btrfs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ void btrfs_printk(struct btrfs_fs_info *fs_info, const char *fmt, ...)
va_start(args, fmt);

if (fmt[0] == '<' && isdigit(fmt[1]) && fmt[2] == '>') {
strncpy(lvl, fmt, 3);
memcpy(lvl, fmt, 3);
lvl[3] = '\0';
fmt += 3;
type = logtypes[fmt[1] - '0'];
} else
Expand Down

0 comments on commit f07c9a7

Please sign in to comment.