From: ian Date: Sat, 22 Sep 2012 07:19:09 +0000 (+0000) Subject: runtime: Reject surrogate pairs in range over string. X-Git-Url: http://git.sourceforge.jp/view?p=pf3gnuchains%2Fgcc-fork.git;a=commitdiff_plain;h=f4e5b55b7a97c4fba23a0bc9801e96f62d8ce4fa runtime: Reject surrogate pairs in range over string. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_7-branch@191639 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/libgo/runtime/go-rune.c b/libgo/runtime/go-rune.c index 7e31eb8d622..acdecb02467 100644 --- a/libgo/runtime/go-rune.c +++ b/libgo/runtime/go-rune.c @@ -53,6 +53,14 @@ __go_get_rune (const unsigned char *str, size_t len, int *rune) *rune = (((c & 0xf) << 12) + ((c1 & 0x3f) << 6) + (c2 & 0x3f)); + + if (*rune >= 0xd800 && *rune < 0xe000) + { + /* Invalid surrogate half; return replace character. */ + *rune = 0xfffd; + return 1; + } + return 3; }