From: Chris Metcalf Date: Tue, 6 Oct 2015 16:37:41 +0000 (-0400) Subject: strscpy: zero any trailing garbage bytes in the destination X-Git-Tag: v4.3-rc5~28^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=990486c8af044f89bddfbde1d1cf9fde449bedbf;p=profile%2Fcommon%2Fplatform%2Fkernel%2Flinux-artik7.git 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 --- diff --git a/lib/string.c b/lib/string.c index 8dbb7b1..84775ba 100644 --- a/lib/string.c +++ b/lib/string.c @@ -203,12 +203,13 @@ ssize_t strscpy(char *dest, const char *src, size_t count) unsigned long c, data; c = *(unsigned long *)(src+res); - *(unsigned long *)(dest+res) = c; if (has_zero(c, &data, &constants)) { data = prep_zero_mask(c, data, &constants); data = create_zero_mask(data); + *(unsigned long *)(dest+res) = c & zero_bytemask(data); return res + find_zero(data); } + *(unsigned long *)(dest+res) = c; res += sizeof(unsigned long); count -= sizeof(unsigned long); max -= sizeof(unsigned long);