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/10100] New: Regression in hsearch_r(): Segmentation fault over internal invariant violation


The modifications of hsearch_r() (see bug#6966) in glibc-2.9 leads to
segmentation faults in some circumstances as a consequence of internal invariant
violation.

Description of the hsearch_r in glibc sources reads:

  We use an trick to speed up the lookup. The table is created by hcreate
  with one more element available. This enables us to use the index zero
  special. *This index will never be used because we store the first hash
  index in the field used where zero means not used.* Every other value
  means used. The used field can be used as a first fast comparison for
  equality of the stored and the parameter value. This helps to prevent
  unnecessary expensive calls of strcmp. 

But the new version stores hash value in the 'used' field instead of table
index, which can be zero. As a result this invariant can be violated and
dereference of uninitialized memory may happen. An example demonstrating the
issue is available here:
http://linuxtesting.org/results/report?num=S0791

Quick fix may be:

   hval = len;
   count = len;
   while (count-- > 0)
     {
       hval <<= 4;
       hval += item.key[count];
     }
+  /* make sure hash value is not zero */
+  if (!hval) hval = 1;
 
   /* First hash function: simply take the modul but prevent zero. */
   idx = hval % htab->size + 1;

But if zero table index is not used special in the new scheme, why do we need to
allocate extra element? So, long term solution requires some more investigation.

-- 
           Summary: Regression in hsearch_r(): Segmentation fault over
                    internal invariant violation
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: drepper at redhat dot com
        ReportedBy: khoroshilov at linuxtesting dot org
                CC: glibc-bugs at sources dot redhat dot com


http://sourceware.org/bugzilla/show_bug.cgi?id=10100

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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