diff options
| author | Kees Cook <[email protected]> | 2013-07-03 22:04:55 +0000 |
|---|---|---|
| committer | Linus Torvalds <[email protected]> | 2013-07-03 23:07:41 +0000 |
| commit | 096a8aac6bf4a5a0b2ef812ad76d056bbf3fb2af (patch) | |
| tree | fa3721d6d2a96f69023624366afecb72e7b60eb6 /fs/hppfs/hppfs.c | |
| parent | err.h: IS_ERR() can accept __user pointers (diff) | |
| download | kernel-096a8aac6bf4a5a0b2ef812ad76d056bbf3fb2af.tar.gz kernel-096a8aac6bf4a5a0b2ef812ad76d056bbf3fb2af.zip | |
clean up scary strncpy(dst, src, strlen(src)) uses
Fix various weird constructions of strncpy(dst, src, strlen(src)).
Length limits should be about the space available in the destination,
not repurposed as a method to either always include or always exclude a
trailing NULL byte. Either the NULL should always be copied (using
strlcpy), or it should not be copied (using something like memcpy).
Readable code should not depend on the weird behavior of strncpy when it
hits the length limit. Better to avoid the anti-pattern entirely.
[[email protected]: revert getdelays.c part due to missing bsd/string.h]
Signed-off-by: Kees Cook <[email protected]>
Acked-by: Greg Kroah-Hartman <[email protected]> [staging]
Acked-by: Rafael J. Wysocki <[email protected]> [acpi]
Cc: Martin Schwidefsky <[email protected]>
Cc: Heiko Carstens <[email protected]>
Cc: Ursula Braun <[email protected]>
Cc: Frank Blaschka <[email protected]>
Cc: Richard Weinberger <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
Diffstat (limited to 'fs/hppfs/hppfs.c')
| -rw-r--r-- | fs/hppfs/hppfs.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/fs/hppfs/hppfs.c b/fs/hppfs/hppfs.c index fc90ab11c340..4338ff32959d 100644 --- a/fs/hppfs/hppfs.c +++ b/fs/hppfs/hppfs.c @@ -69,7 +69,7 @@ static char *dentry_name(struct dentry *dentry, int extra) struct dentry *parent; char *root, *name; const char *seg_name; - int len, seg_len; + int len, seg_len, root_len; len = 0; parent = dentry; @@ -81,7 +81,8 @@ static char *dentry_name(struct dentry *dentry, int extra) } root = "proc"; - len += strlen(root); + root_len = strlen(root); + len += root_len; name = kmalloc(len + extra + 1, GFP_KERNEL); if (name == NULL) return NULL; @@ -91,7 +92,7 @@ static char *dentry_name(struct dentry *dentry, int extra) while (parent->d_parent != parent) { if (is_pid(parent)) { seg_name = "pid"; - seg_len = strlen("pid"); + seg_len = strlen(seg_name); } else { seg_name = parent->d_name.name; @@ -100,10 +101,10 @@ static char *dentry_name(struct dentry *dentry, int extra) len -= seg_len + 1; name[len] = '/'; - strncpy(&name[len + 1], seg_name, seg_len); + memcpy(&name[len + 1], seg_name, seg_len); parent = parent->d_parent; } - strncpy(name, root, strlen(root)); + memcpy(name, root, root_len); return name; } |
