[RFC/PATCH] memcpy-ssse3: add overlap checks

Felipe Contreras felipe.contreras@gmail.com
Wed Apr 13 12:39:00 GMT 2011


On Tue, Apr 12, 2011 at 7:54 PM, Ulrich Drepper <drepper@gmail.com> wrote:
> No.  This does not belong into the production code.
>
> If you have crappy code to run which is not adequately tested then
> handle this outside the libc.  Just use a preloadable module.  It's
> trivial, you can even add it to /etc/ld.so.preload.  Use code like

Ok, I didn't know it was possible to have an ld preload systemwide, I
searched for that but somehow didn't find it.

Here's my proposal for the check though:

---
#include <string.h>

extern void __fortify_fail(const char *msg);

void *memcpy(void *dst, const void *src, size_t n)
{
	if (dst >= src + n || src >= dst + n)
		goto ok;
	__fortify_fail("memcpy overlap");
ok:
	return memmove(dst, src, n);
}
---

-- 
Felipe Contreras



More information about the Libc-alpha mailing list