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.
Showing the changes to lib/string.c (1 of 1 file). Show all
Unified · Split
| @@ -203,12 +203,13 @@ ssize_t strscpy(char *dest, const char *src, size_t count) · 202 unmodified lines | ||
| 203 | 203 | unsigned long c, data; |
| 204 | 204 | |
| 205 | 205 | c = *(unsigned long *)(src+res); |
| 206 | − *(unsigned long *)(dest+res) = c; | |
| 207 | 206 | if (has_zero(c, &data, &constants)) { |
| 208 | 207 | data = prep_zero_mask(c, data, &constants); |
| 209 | 208 | data = create_zero_mask(data); |
| 209 | + *(unsigned long *)(dest+res) = c & zero_bytemask(data); | |
| 210 | 210 | return res + find_zero(data); |
| 211 | 211 | } |
| 212 | + *(unsigned long *)(dest+res) = c; | |
| 212 | 213 | res += sizeof(unsigned long); |
| 213 | 214 | count -= sizeof(unsigned long); |
| 214 | 215 | max -= sizeof(unsigned long); |