Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > bee470e21a8ce2cdd844d7d805aa403d > files > 65

glibc-2.5-49.el5_5.6.src.rpm

2007-11-07  Ulrich Drepper  <drepper@redhat.com>

	[BZ #5277]
	* iconv/loop.c (STANDARD_TO_LOOP_ERR_HANDLER): If conversion failed
	because output buffer is too small break, don't loop.
	* iconvdata/Makefile (tests): Add bug-iconv6.
	* iconvdata/bug-iconv6.c: New file.

--- libc/iconv/loop.c	25 Sep 2005 16:42:36 -0000	1.36
+++ libc/iconv/loop.c	7 Nov 2007 23:58:39 -0000	1.37
@@ -225,7 +225,12 @@
       }									      \
     /* If any of them recognized the input continue with the loop.  */	      \
     if (result != __GCONV_ILLEGAL_INPUT)				      \
-      continue;								      \
+      {									      \
+	if (__builtin_expect (result == __GCONV_FULL_OUTPUT, 0))	      \
+	  break;							      \
+									      \
+	continue;							      \
+      }									      \
 									      \
     /* Next see whether we have to ignore the error.  If not, stop.  */	      \
     if (! ignore_errors_p ())						      \
--- libc/iconvdata/Makefile	30 Sep 2007 04:00:02 -0000	1.151
+++ libc/iconvdata/Makefile	7 Nov 2007 23:58:21 -0000	1.152
@@ -66,7 +66,7 @@ include ../Makeconfig
 
 ifeq (yes,$(build-shared))
 tests = bug-iconv1 bug-iconv2 tst-loading tst-e2big tst-iconv4 bug-iconv4 \
-	tst-iconv6
+	tst-iconv6 bug-iconv6
 ifeq ($(have-thread-library),yes)
 tests += bug-iconv3
 endif
--- libc/iconvdata/bug-iconv6.c	1 Jan 1970 00:00:00 -0000
+++ libc/iconvdata/bug-iconv6.c	7 Nov 2007 23:58:04 -0000	1.1
@@ -0,0 +1,52 @@
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <iconv.h>
+#include <locale.h>
+
+static const char testbuf[] = {
+	0xEF, 0xBE, 0x9F, 0xD0, 0xB4, 0xEF, 0xBE, 0x9F, 0x29, 0xEF, 0xBE, 0x8E,
+	0xEF, 0xBE, 0x9F, 0xEF, 0xBD, 0xB6, 0xEF, 0xBD, 0xB0, 0xEF, 0xBE, 0x9D
+};
+
+static int
+do_test (void)
+{
+  setlocale (LC_ALL, "en_US.UTF-8");
+  iconv_t ic = iconv_open ("ISO-2022-JP//TRANSLIT", "UTF-8");
+  if (ic == (iconv_t) -1)
+    {
+      puts ("iconv_open failed");
+      return 1;
+    }
+  size_t outremain = sizeof testbuf;
+  char outbuf[outremain];
+  char *inp = (char *) testbuf;
+  char *outp = outbuf;
+  size_t inremain = sizeof testbuf;
+
+  int ret = iconv (ic, &inp, &inremain, &outp, &outremain);
+
+  int result = 0;
+  if (ret == (size_t) -1)
+    {
+      if (errno == E2BIG)
+	puts ("buffer too small reported.  OK");
+      else
+	{
+	  printf ("iconv failed with %d (%m)\n", errno);
+	  result = 0;
+	}
+    }
+  else
+    {
+      printf ("iconv returned %d\n", ret);
+      result = 1;
+    }
+
+  return result;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"