On 04/18 07:21, Otto Moerbeek wrote:
> On Mon, Apr 17, 2017 at 05:26:52PM -0700, Jeremy Evans wrote:
>
> > posix_memalign doesn't seem to work with malloc canaries
> > in some allocations. This appears to be what caused the
> > issue malloc canary failure in ruby when the page size
> > was accidentally set to high. Example:
> >
> > #include <stdlib.h>
> >
> > char *malloc_options = "C";
> >
> > int main(int argc, char** argv){
> > void *v;
> > posix_memalign(&v, 8192, 8192-40);
> > free(v);
> > exit(0);
> > }
>
> Try this,
>
> -Otto
Otto,
This appears to fix the issue, both in my test code and with ruby.
I'm not a malloc hacker, but it looks correct to me, so OK jeremy@.
Thanks,
Jeremy
>
> Index: malloc.c
> ===================================================================
> RCS file: /cvs/src/lib/libc/stdlib/malloc.c,v
> retrieving revision 1.222
> diff -u -p -r1.222 malloc.c
> --- malloc.c 17 Apr 2017 16:36:35 -0000 1.222
> +++ malloc.c 18 Apr 2017 05:21:13 -0000
> @@ -2018,6 +2018,9 @@ omemalign(struct dir_info *pool, size_t
> else
> memset(p, SOME_JUNK, psz - mopts.malloc_guard);
> }
> + else if (mopts.chunk_canaries)
> + fill_canary(p, sz - mopts.malloc_guard,
> + psz - mopts.malloc_guard);
>
> return p;
> }