51f0aa
Upstream commit:
51f0aa
51f0aa
commit 7e2f0d2d77e4bc273fe00f99d970605d8e38d4d6
51f0aa
Author: Andreas Schwab <schwab@suse.de>
51f0aa
Date:   Mon Feb 4 10:16:33 2013 +0100
51f0aa
51f0aa
    Fix handling of collating symbols in regexps
51f0aa
ce426f
From c1b97d6d896b1f22fdf5d28471ef7859ec840a57 Mon Sep 17 00:00:00 2001
ce426f
From: Andreas Schwab <schwab@redhat.com>
ce426f
Date: Wed, 1 Sep 2010 17:26:15 +0200
ce426f
Subject: [PATCH] Fix handling of collating symbols in regexps
ce426f
ce426f
[BZ #11561]
ce426f
* posix/regcomp.c (parse_bracket_exp): When looking up collating
ce426f
elements compare against the byte sequence of it, not its name.
ce426f
ce426f
---
ce426f
 ChangeLog       |    4 +++
ce426f
 posix/regcomp.c |   72 ++++++++++++++++++++----------------------------------
ce426f
 2 files changed, 31 insertions(+), 45 deletions(-)
ce426f
ce426f
--- glibc-2.17-c758a686/posix/regcomp.c
ce426f
+++ glibc-2.17-c758a686/posix/regcomp.c
ce426f
@@ -2772,40 +2772,29 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
ce426f
 
ce426f
   /* Local function for parse_bracket_exp used in _LIBC environement.
ce426f
      Seek the collating symbol entry correspondings to NAME.
ce426f
-     Return the index of the symbol in the SYMB_TABLE.  */
ce426f
+     Return the index of the symbol in the SYMB_TABLE,
ce426f
+     or -1 if not found.  */
ce426f
 
ce426f
   auto inline int32_t
ce426f
   __attribute ((always_inline))
ce426f
-  seek_collating_symbol_entry (name, name_len)
ce426f
-	 const unsigned char *name;
ce426f
-	 size_t name_len;
ce426f
+  seek_collating_symbol_entry (const unsigned char *name, size_t name_len)
ce426f
     {
ce426f
-      int32_t hash = elem_hash ((const char *) name, name_len);
ce426f
-      int32_t elem = hash % table_size;
ce426f
-      if (symb_table[2 * elem] != 0)
ce426f
-	{
ce426f
-	  int32_t second = hash % (table_size - 2) + 1;
ce426f
-
ce426f
-	  do
ce426f
-	    {
ce426f
-	      /* First compare the hashing value.  */
ce426f
-	      if (symb_table[2 * elem] == hash
ce426f
-		  /* Compare the length of the name.  */
ce426f
-		  && name_len == extra[symb_table[2 * elem + 1]]
ce426f
-		  /* Compare the name.  */
ce426f
-		  && memcmp (name, &extra[symb_table[2 * elem + 1] + 1],
ce426f
-			     name_len) == 0)
ce426f
-		{
ce426f
-		  /* Yep, this is the entry.  */
ce426f
-		  break;
ce426f
-		}
ce426f
+      int32_t elem;
ce426f
 
ce426f
-	      /* Next entry.  */
ce426f
-	      elem += second;
ce426f
-	    }
ce426f
-	  while (symb_table[2 * elem] != 0);
ce426f
-	}
ce426f
-      return elem;
ce426f
+      for (elem = 0; elem < table_size; elem++)
ce426f
+	if (symb_table[2 * elem] != 0)
ce426f
+	  {
ce426f
+	    int32_t idx = symb_table[2 * elem + 1];
ce426f
+	    /* Skip the name of collating element name.  */
ce426f
+	    idx += 1 + extra[idx];
ce426f
+	    if (/* Compare the length of the name.  */
ce426f
+		name_len == extra[idx]
ce426f
+		/* Compare the name.  */
ce426f
+		&& memcmp (name, &extra[idx + 1], name_len) == 0)
ce426f
+	      /* Yep, this is the entry.  */
ce426f
+	      return elem;
ce426f
+	  }
ce426f
+      return -1;
ce426f
     }
ce426f
 
ce426f
   /* Local function for parse_bracket_exp used in _LIBC environment.
ce426f
@@ -2814,8 +2803,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
ce426f
 
ce426f
   auto inline unsigned int
ce426f
   __attribute ((always_inline))
ce426f
-  lookup_collation_sequence_value (br_elem)
ce426f
-	 bracket_elem_t *br_elem;
ce426f
+  lookup_collation_sequence_value (bracket_elem_t *br_elem)
ce426f
     {
ce426f
       if (br_elem->type == SB_CHAR)
ce426f
 	{
ce426f
@@ -2843,7 +2831,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
ce426f
 	      int32_t elem, idx;
ce426f
 	      elem = seek_collating_symbol_entry (br_elem->opr.name,
ce426f
 						  sym_name_len);
ce426f
-	      if (symb_table[2 * elem] != 0)
ce426f
+	      if (elem != -1)
ce426f
 		{
ce426f
 		  /* We found the entry.  */
ce426f
 		  idx = symb_table[2 * elem + 1];
ce426f
@@ -2861,7 +2849,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
ce426f
 		  /* Return the collation sequence value.  */
ce426f
 		  return *(unsigned int *) (extra + idx);
ce426f
 		}
ce426f
-	      else if (symb_table[2 * elem] == 0 && sym_name_len == 1)
ce426f
+	      else if (sym_name_len == 1)
ce426f
 		{
ce426f
 		  /* No valid character.  Match it as a single byte
ce426f
 		     character.  */
ce426f
@@ -2883,11 +2871,8 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
ce426f
 
ce426f
   auto inline reg_errcode_t
ce426f
   __attribute ((always_inline))
ce426f
-  build_range_exp (sbcset, mbcset, range_alloc, start_elem, end_elem)
ce426f
-	 re_charset_t *mbcset;
ce426f
-	 int *range_alloc;
ce426f
-	 bitset_t sbcset;
ce426f
-	 bracket_elem_t *start_elem, *end_elem;
ce426f
+  build_range_exp (bitset_t sbcset, re_charset_t *mbcset, int *range_alloc,
ce426f
+		   bracket_elem_t *start_elem, bracket_elem_t *end_elem)
ce426f
     {
ce426f
       unsigned int ch;
ce426f
       uint32_t start_collseq;
ce426f
@@ -2966,25 +2951,22 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
ce426f
 
ce426f
   auto inline reg_errcode_t
ce426f
   __attribute ((always_inline))
ce426f
-  build_collating_symbol (sbcset, mbcset, coll_sym_alloc, name)
ce426f
-	 re_charset_t *mbcset;
ce426f
-	 int *coll_sym_alloc;
ce426f
-	 bitset_t sbcset;
ce426f
-	 const unsigned char *name;
ce426f
+  build_collating_symbol (bitset_t sbcset, re_charset_t *mbcset,
ce426f
+			  int *coll_sym_alloc, const unsigned char *name)
ce426f
     {
ce426f
       int32_t elem, idx;
ce426f
       size_t name_len = strlen ((const char *) name);
ce426f
       if (nrules != 0)
ce426f
 	{
ce426f
 	  elem = seek_collating_symbol_entry (name, name_len);
ce426f
-	  if (symb_table[2 * elem] != 0)
ce426f
+	  if (elem != -1)
ce426f
 	    {
ce426f
 	      /* We found the entry.  */
ce426f
 	      idx = symb_table[2 * elem + 1];
ce426f
 	      /* Skip the name of collating element name.  */
ce426f
 	      idx += 1 + extra[idx];
ce426f
 	    }
ce426f
-	  else if (symb_table[2 * elem] == 0 && name_len == 1)
ce426f
+	  else if (name_len == 1)
ce426f
 	    {
ce426f
 	      /* No valid character, treat it as a normal
ce426f
 		 character.  */