Blame SOURCES/glibc-rh905877.patch

147e83
#
147e83
# Backported from upstream.
147e83
#
147e83
# commit a445af0bc722d620afed7683cd320c0e4c7c6059
147e83
# Author: Andreas Schwab <schwab@suse.de>
147e83
# Date:   Tue Jan 29 14:45:15 2013 +0100
147e83
#
147e83
#    Fix buffer overrun in regexp matcher
147e83
#
147e83
# ChangeLog/
147e83
# 2013-02-12  Andreas Schwab  <schwab@suse.de>
147e83
# 
147e83
#	[BZ #15078]
147e83
#	* posix/regexec.c (extend_buffers): Add parameter min_len.
147e83
#	(check_matching): Pass minimum needed length.
147e83
#	(clean_state_log_if_needed): Likewise.
147e83
#	(get_subexp): Likewise.
147e83
#	* posix/Makefile (tests): Add bug-regex34.
147e83
#	(bug-regex34-ENV): Define.
147e83
#	* posix/bug-regex34.c: New file.
147e83
#
147e83
--- glibc-2.17-c758a686/posix/Makefile	2012-12-24 22:02:13.000000000 -0500
147e83
+++ glibc-2.17-c758a686/posix/Makefile	2013-03-17 15:30:13.121068666 -0400
147e83
@@ -86,7 +86,7 @@
147e83
 		   tst-rfc3484-3 \
147e83
 		   tst-getaddrinfo3 tst-fnmatch2 tst-cpucount tst-cpuset \
147e83
 		   bug-getopt1 bug-getopt2 bug-getopt3 bug-getopt4 \
147e83
-		   bug-getopt5 tst-getopt_long1
147e83
+		   bug-getopt5 tst-getopt_long1 bug-regex34
147e83
 xtests		:= bug-ga2
147e83
 ifeq (yes,$(build-shared))
147e83
 test-srcs	:= globtest
147e83
@@ -195,6 +195,7 @@
147e83
 bug-regex30-ENV = LOCPATH=$(common-objpfx)localedata
147e83
 bug-regex32-ENV = LOCPATH=$(common-objpfx)localedata
147e83
 bug-regex33-ENV = LOCPATH=$(common-objpfx)localedata
147e83
+bug-regex34-ENV = LOCPATH=$(common-objpfx)localedata
147e83
 tst-rxspencer-ARGS = --utf8 rxspencer/tests
147e83
 tst-rxspencer-ENV = LOCPATH=$(common-objpfx)localedata
147e83
 tst-pcre-ARGS = PCRE.tests
147e83
diff --git glibc-2.17-c758a686/posix/bug-regex34.c glibc-2.17-c758a686/posix/bug-regex34.c
147e83
new file mode 100644
147e83
index 0000000..bb3b613
147e83
--- /dev/null
147e83
+++ glibc-2.17-c758a686/posix/bug-regex34.c
147e83
@@ -0,0 +1,46 @@
147e83
+/* Test re_search with multi-byte characters in UTF-8.
147e83
+   Copyright (C) 2013 Free Software Foundation, Inc.
147e83
+   This file is part of the GNU C Library.
147e83
+
147e83
+   The GNU C Library is free software; you can redistribute it and/or
147e83
+   modify it under the terms of the GNU Lesser General Public
147e83
+   License as published by the Free Software Foundation; either
147e83
+   version 2.1 of the License, or (at your option) any later version.
147e83
+
147e83
+   The GNU C Library is distributed in the hope that it will be useful,
147e83
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
147e83
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
147e83
+   Lesser General Public License for more details.
147e83
+
147e83
+   You should have received a copy of the GNU Lesser General Public
147e83
+   License along with the GNU C Library; if not, see
147e83
+   <http://www.gnu.org/licenses/>.  */
147e83
+
147e83
+#define _GNU_SOURCE 1
147e83
+#include <stdio.h>
147e83
+#include <string.h>
147e83
+#include <locale.h>
147e83
+#include <regex.h>
147e83
+
147e83
+static int
147e83
+do_test (void)
147e83
+{
147e83
+  struct re_pattern_buffer r;
147e83
+  /* ကျွန်ုပ်x */
147e83
+  const char *s = "\xe1\x80\x80\xe1\x80\xbb\xe1\x80\xbd\xe1\x80\x94\xe1\x80\xba\xe1\x80\xaf\xe1\x80\x95\xe1\x80\xbax";
147e83
+
147e83
+  if (setlocale (LC_ALL, "en_US.UTF-8") == NULL)
147e83
+    {
147e83
+      puts ("setlocale failed");
147e83
+      return 1;
147e83
+    }
147e83
+  memset (&r, 0, sizeof (r));
147e83
+
147e83
+  re_compile_pattern ("[^x]x", 5, &r);
147e83
+  /* This was triggering a buffer overflow.  */
147e83
+  re_search (&r, s, strlen (s), 0, strlen (s), 0);
147e83
+  return 0;
147e83
+}
147e83
+
147e83
+#define TEST_FUNCTION do_test ()
147e83
+#include "../test-skeleton.c"
147e83
diff --git glibc-2.17-c758a686/posix/regexec.c glibc-2.17-c758a686/posix/regexec.c
147e83
index 7f2de85..5ca2bf6 100644
147e83
--- glibc-2.17-c758a686/posix/regexec.c
147e83
+++ glibc-2.17-c758a686/posix/regexec.c
147e83
@@ -197,7 +197,7 @@ static int group_nodes_into_DFAstates (const re_dfa_t *dfa,
147e83
 static int check_node_accept (const re_match_context_t *mctx,
147e83
 			      const re_token_t *node, int idx)
147e83
      internal_function;
147e83
-static reg_errcode_t extend_buffers (re_match_context_t *mctx)
147e83
+static reg_errcode_t extend_buffers (re_match_context_t *mctx, int min_len)
147e83
      internal_function;
147e83
 
147e83
 /* Entry point for POSIX code.  */
147e83
@@ -1160,7 +1160,7 @@ check_matching (re_match_context_t *mctx, int fl_longest_match,
147e83
 	  || (BE (next_char_idx >= mctx->input.valid_len, 0)
147e83
 	      && mctx->input.valid_len < mctx->input.len))
147e83
 	{
147e83
-	  err = extend_buffers (mctx);
147e83
+	  err = extend_buffers (mctx, next_char_idx + 1);
147e83
 	  if (BE (err != REG_NOERROR, 0))
147e83
 	    {
147e83
 	      assert (err == REG_ESPACE);
147e83
@@ -1738,7 +1738,7 @@ clean_state_log_if_needed (re_match_context_t *mctx, int next_state_log_idx)
147e83
 	  && mctx->input.valid_len < mctx->input.len))
147e83
     {
147e83
       reg_errcode_t err;
147e83
-      err = extend_buffers (mctx);
147e83
+      err = extend_buffers (mctx, next_state_log_idx + 1);
147e83
       if (BE (err != REG_NOERROR, 0))
147e83
 	return err;
147e83
     }
147e83
@@ -2792,7 +2792,7 @@ get_subexp (re_match_context_t *mctx, int bkref_node, int bkref_str_idx)
147e83
 		  if (bkref_str_off >= mctx->input.len)
147e83
 		    break;
147e83
 
147e83
-		  err = extend_buffers (mctx);
147e83
+		  err = extend_buffers (mctx, bkref_str_off + 1);
147e83
 		  if (BE (err != REG_NOERROR, 0))
147e83
 		    return err;
147e83
 
147e83
@@ -4102,7 +4102,7 @@ check_node_accept (const re_match_context_t *mctx, const re_token_t *node,
147e83
 
147e83
 static reg_errcode_t
147e83
 internal_function __attribute_warn_unused_result__
147e83
-extend_buffers (re_match_context_t *mctx)
147e83
+extend_buffers (re_match_context_t *mctx, int min_len)
147e83
 {
147e83
   reg_errcode_t ret;
147e83
   re_string_t *pstr = &mctx->input;
147e83
@@ -4111,8 +4111,10 @@ extend_buffers (re_match_context_t *mctx)
147e83
   if (BE (INT_MAX / 2 / sizeof (re_dfastate_t *) <= pstr->bufs_len, 0))
147e83
     return REG_ESPACE;
147e83
 
147e83
-  /* Double the lengthes of the buffers.  */
147e83
-  ret = re_string_realloc_buffers (pstr, MIN (pstr->len, pstr->bufs_len * 2));
147e83
+  /* Double the lengthes of the buffers, but allocate at least MIN_LEN.  */
147e83
+  ret = re_string_realloc_buffers (pstr,
147e83
+				   MAX (min_len,
147e83
+					MIN (pstr->len, pstr->bufs_len * 2)));
147e83
   if (BE (ret != REG_NOERROR, 0))
147e83
     return ret;
147e83