[Bug libc/18240] hcreate((size_t)-1) should fail with ENOMEM

fweimer at redhat dot com sourceware-bugzilla@sourceware.org
Mon Apr 20 08:29:00 GMT 2015


https://sourceware.org/bugzilla/show_bug.cgi?id=18240

--- Comment #2 from Florian Weimer <fweimer at redhat dot com> ---
Reproducer for the out-of-bounds access:

#include <err.h>
#include <errno.h>
#include <search.h>
#include <stdio.h>

int
main (void)
{
  int res = hcreate (-1);
  if (res == 0)
    {
      if (errno == ENOMEM)
    return 0;
      printf ("hcreate(-1): %m\n");
      return 1;
    }
  for (int i = 0; i < 100; ++i)
    {
      char key[20];
      snprintf (key, sizeof (key), "%d", i);
      ENTRY e = { key, "value" };
      if (hsearch (e, ENTER) == NULL)
    {
      printf ("hsearch(\"%s\"): %m\n", key);
      return 1;
    }
    }
  hdestroy ();
  return 0;
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.



More information about the Glibc-bugs mailing list