[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#36321: ix86 direction flag not preserved over strstr() call



Package: libc6
Version: 2.1.1

The definition of strstr(3) in ./sysdeps/i386/i486/bits/string.h
includes a fragment of assembly:

__STRING_INLINE char *
__strstr_cg (__const char *__haystack, __const char __needle[],
             size_t __needle_len)
{
  register unsigned long int __d0, __d1, __d2;
  register char *__res;
  __asm__ __volatile__
    ("cld\n" \
     "1:\n\t"
     "movl      %6,%%edi\n\t"
     "movl      %5,%%eax\n\t"
     "movl      %4,%%ecx\n\t"
     "repe; cmpsb\n\t"
     "je        2f\n\t"
     "cmpb      $0,-1(%%esi)\n\t"
     "leal      1(%%eax),%5\n\t"
     "jne       1b\n\t"
     "xorl      %%eax,%%eax\n"
     "2:"
     : "=a" (__res), "=&S" (__d0), "=&D" (__d1), "=&c" (__d2)
     : "g" (__needle_len), "1" (__haystack), "d" (__needle)
     : "cc");
  return __res;
}

Note that it clears the direction flag (cld), but never restores it to
its previous value.  This could be a problem if someone sets the
direction bit in EFLAGS.  This same problem is present in quite a few
other functions in string.h

Austin


Reply to: