This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]