From: Ian Lance Taylor Date: Sat, 22 Sep 2012 07:18:45 +0000 (+0000) Subject: runtime: Reject surrogate pairs in range over string. X-Git-Tag: misc/gccgo-go1_1_2~690 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a2383b317b9d082d5d8d1661d61adc3d902efa83;p=thirdparty%2Fgcc.git runtime: Reject surrogate pairs in range over string. From-SVN: r191638 --- diff --git a/libgo/runtime/go-rune.c b/libgo/runtime/go-rune.c index 7e31eb8d6229..acdecb02467b 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; }