Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1239728
| From | Ingo Molnar <mingo@kernel.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH] string: Improve the generic strlcpy() implementation |
| Date | 2015-10-05 18:30 +0200 |
| Message-ID | <qggOd-4bm-7@gated-at.bofh.it> (permalink) |
| References | <qgg1P-30J-3@gated-at.bofh.it> <qggOd-4bm-5@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
* Linus Torvalds <torvalds@linux-foundation.org> wrote:
> > 2) strscpy() will copy garbage past NUL from source into destination. It won't
> > fault but still, who knows what lies after string.
>
> Yes, that's probably worth fixing before we get actual users..
Hm, this is the spot:
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);
return res + find_zero(data);
}
We could do something like:
c = *(unsigned long *)(src+res);
*(unsigned long *)(dest+res) = c;
if (has_zero(c, &data, &constants)) {
unsigned int zero_pos;
data = prep_zero_mask(c, data, &constants);
data = create_zero_mask(data);
zero_pos = find_zero(data);
res += zero_pos;
memset(dest+res, 0, sizeof(long)-zero_pos);
return res;
}
I.e. the extra memset() clears out the partial word (if any) after the NUL.
Completely untested.
Thanks,
Ingo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: [PATCH] string: Improve the generic strlcpy() implementation Alexey Dobriyan <adobriyan@gmail.com> - 2015-10-05 17:40 +0200
Re: [PATCH] string: Improve the generic strlcpy() implementation Ingo Molnar <mingo@kernel.org> - 2015-10-05 18:20 +0200
Re: [PATCH] string: Improve the generic strlcpy() implementation Ingo Molnar <mingo@kernel.org> - 2015-10-05 18:20 +0200
Re: [PATCH] string: Improve the generic strlcpy() implementation Ingo Molnar <mingo@kernel.org> - 2015-10-05 18:30 +0200
[PATCH] string: Fix strscpy() uninitialized data copy bug Ingo Molnar <mingo@kernel.org> - 2015-10-05 18:40 +0200
Re: [PATCH] string: Fix strscpy() uninitialized data copy bug Chris Metcalf <cmetcalf@ezchip.com> - 2015-10-05 21:00 +0200
Re: [PATCH] string: Fix strscpy() uninitialized data copy bug Ingo Molnar <mingo@kernel.org> - 2015-10-06 09:30 +0200
Re: [PATCH] string: Improve the generic strlcpy() implementation Ingo Molnar <mingo@kernel.org> - 2015-10-05 18:30 +0200
Re: [PATCH] string: Improve the generic strlcpy() implementation Linus Torvalds <torvalds@linux-foundation.org> - 2015-10-05 22:50 +0200
Re: [PATCH] strscpy: zero any trailing garbage bytes in the destination Ingo Molnar <mingo@kernel.org> - 2015-10-07 09:30 +0200
csiph-web