summaryrefslogtreecommitdiffstats
path: root/lib/string.c
diff options
context:
space:
mode:
authorChris Metcalf <cmetcalf@ezchip.com>2015-10-06 12:37:41 -0400
committerChris Metcalf <cmetcalf@ezchip.com>2015-10-06 14:53:18 -0400
commit990486c8af044f89bddfbde1d1cf9fde449bedbf (patch)
tree145c16309dfc5586b5120d7b7c7d585337e8d5d1 /lib/string.c
parentc753bf34c94e5ac901e625e52f47320eeec4de2d (diff)
strscpy: zero any trailing garbage bytes in the destination
It's possible that the destination can be shadowed in userspace (as, for example, the perf buffers are now). So we should take care not to leak data that could be inspected by userspace. Signed-off-by: Chris Metcalf <cmetcalf@ezchip.com>
Diffstat (limited to 'lib/string.c')
-rw-r--r--lib/string.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/string.c b/lib/string.c
index 8dbb7b1eab50..84775ba873b9 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -203,12 +203,13 @@ ssize_t strscpy(char *dest, const char *src, size_t count)
203 unsigned long c, data; 203 unsigned long c, data;
204 204
205 c = *(unsigned long *)(src+res); 205 c = *(unsigned long *)(src+res);
206 *(unsigned long *)(dest+res) = c;
207 if (has_zero(c, &data, &constants)) { 206 if (has_zero(c, &data, &constants)) {
208 data = prep_zero_mask(c, data, &constants); 207 data = prep_zero_mask(c, data, &constants);
209 data = create_zero_mask(data); 208 data = create_zero_mask(data);
209 *(unsigned long *)(dest+res) = c & zero_bytemask(data);
210 return res + find_zero(data); 210 return res + find_zero(data);
211 } 211 }
212 *(unsigned long *)(dest+res) = c;
212 res += sizeof(unsigned long); 213 res += sizeof(unsigned long);
213 count -= sizeof(unsigned long); 214 count -= sizeof(unsigned long);
214 max -= sizeof(unsigned long); 215 max -= sizeof(unsigned long);