This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
bug in ISO-2022-KR converter
- From: Bruno Haible <bruno at clisp dot org>
- To: libc-alpha at sources dot redhat dot com
- Date: Mon, 22 Apr 2002 14:05:18 +0200 (CEST)
- Subject: bug in ISO-2022-KR converter
The checking of inptr before accessing inptr[1], inptr[2] etc. in the
ISO-2022-KR converter is wrong: inptr + 1 <= inend is not a guarantee
that inptr[1] can be accessed. You need inptr + 2 <= inend for that.
Also the MAX_NEEDED_FROM value is too low.
2002-04-20 Bruno Haible <bruno@clisp.org>
* iconvdata/iso-2002-kr.c (MAX_NEEDED_FROM): Set to 4.
(BODY for FROM_LOOP): Fix comparisons between inptr and inend.
--- glibc-20020408/iconvdata/iso-2022-kr.c.bak 2001-08-15 21:39:08.000000000 +0200
+++ glibc-20020408/iconvdata/iso-2022-kr.c 2002-04-21 02:49:47.000000000 +0200
@@ -1,5 +1,5 @@
/* Conversion module for ISO-2022-KR.
- Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2000-2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
@@ -40,7 +40,7 @@
#define FROM_LOOP from_iso2022kr_loop
#define TO_LOOP to_iso2022kr_loop
#define MIN_NEEDED_FROM 1
-#define MAX_NEEDED_FROM 3
+#define MAX_NEEDED_FROM 4
#define MIN_NEEDED_TO 4
#define MAX_NEEDED_TO 4
#define PREPARE_LOOP \
@@ -139,12 +139,11 @@
switching is done using the SI and SO bytes. But we have to \
recognize `Esc $ ) C' since this is a kind of flag for this \
encoding. We simply ignore it. */ \
- if (__builtin_expect (inptr + 1 > inend, 0) \
+ if (__builtin_expect (inptr + 2 > inend, 0) \
|| (inptr[1] == '$' \
- && (__builtin_expect (inptr + 2 > inend, 0) \
+ && (__builtin_expect (inptr + 3 > inend, 0) \
|| (inptr[2] == ')' \
- && __builtin_expect (inptr + 3 > inend, 0))))) \
- \
+ && __builtin_expect (inptr + 4 > inend, 0))))) \
{ \
result = __GCONV_INCOMPLETE_INPUT; \
break; \