aboutsummaryrefslogtreecommitdiffstats
path: root/fs/hppfs
diff options
context:
space:
mode:
authorKees Cook <keescook@chromium.org>2013-07-03 18:04:55 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-07-03 19:07:41 -0400
commit096a8aac6bf4a5a0b2ef812ad76d056bbf3fb2af (patch)
treefa3721d6d2a96f69023624366afecb72e7b60eb6 /fs/hppfs
parente7152b97f38f1f5b915c719e6a3040697a700a16 (diff)
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. [akpm@linux-foundation.org: revert getdelays.c part due to missing bsd/string.h] Signed-off-by: Kees Cook <keescook@chromium.org> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> [staging] Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> [acpi] Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: Ursula Braun <ursula.braun@de.ibm.com> Cc: Frank Blaschka <blaschka@linux.vnet.ibm.com> Cc: Richard Weinberger <richard@nod.at> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/hppfs')
-rw-r--r--fs/hppfs/hppfs.c11
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)
69 struct dentry *parent; 69 struct dentry *parent;
70 char *root, *name; 70 char *root, *name;
71 const char *seg_name; 71 const char *seg_name;
72 int len, seg_len; 72 int len, seg_len, root_len;
73 73
74 len = 0; 74 len = 0;
75 parent = dentry; 75 parent = dentry;
@@ -81,7 +81,8 @@ static char *dentry_name(struct dentry *dentry, int extra)
81 } 81 }
82 82
83 root = "proc"; 83 root = "proc";
84 len += strlen(root); 84 root_len = strlen(root);
85 len += root_len;
85 name = kmalloc(len + extra + 1, GFP_KERNEL); 86 name = kmalloc(len + extra + 1, GFP_KERNEL);
86 if (name == NULL) 87 if (name == NULL)
87 return NULL; 88 return NULL;
@@ -91,7 +92,7 @@ static char *dentry_name(struct dentry *dentry, int extra)
91 while (parent->d_parent != parent) { 92 while (parent->d_parent != parent) {
92 if (is_pid(parent)) { 93 if (is_pid(parent)) {
93 seg_name = "pid"; 94 seg_name = "pid";
94 seg_len = strlen("pid"); 95 seg_len = strlen(seg_name);
95 } 96 }
96 else { 97 else {
97 seg_name = parent->d_name.name; 98 seg_name = parent->d_name.name;
@@ -100,10 +101,10 @@ static char *dentry_name(struct dentry *dentry, int extra)
100 101
101 len -= seg_len + 1; 102 len -= seg_len + 1;
102 name[len] = '/'; 103 name[len] = '/';
103 strncpy(&name[len + 1], seg_name, seg_len); 104 memcpy(&name[len + 1], seg_name, seg_len);
104 parent = parent->d_parent; 105 parent = parent->d_parent;
105 } 106 }
106 strncpy(name, root, strlen(root)); 107 memcpy(name, root, root_len);
107 return name; 108 return name;
108} 109}
109 110