[Pkg-mono-svn-commits] [mono] 01/03: [eglib] Fixed g_utf8_to_utf16_general() to handle invalid utf8 (cherry picked from commit a81cd6dae81a7077a7f014948c78075da08f02f7)
Jo Shields
directhex at alioth.debian.org
Sat Oct 12 23:53:17 UTC 2013
This is an automated email from the git hooks/post-receive script.
directhex pushed a commit to annotated tag debian/3.0.6+dfsg2-7
in repository mono.
commit 235060d86f87c6bb8dac8d0e40b598a248c0599b
Author: Jeffrey Stedfast <fejj at gnome.org>
Date: Wed Aug 14 19:40:59 2013 -0400
[eglib] Fixed g_utf8_to_utf16_general() to handle invalid utf8
(cherry picked from commit a81cd6dae81a7077a7f014948c78075da08f02f7)
---
eglib/src/giconv.c | 57 +++++++++++++++++++++++++++++++---------------------
1 file changed, 34 insertions(+), 23 deletions(-)
diff --git a/eglib/src/giconv.c b/eglib/src/giconv.c
index 2f44336..da48c6f 100644
--- a/eglib/src/giconv.c
+++ b/eglib/src/giconv.c
@@ -894,7 +894,7 @@ eg_utf8_to_utf16_general (const gchar *str, glong len, glong *items_read, glong
size_t inleft;
char *inptr;
gunichar c;
- int n;
+ int u, n;
g_return_val_if_fail (str != NULL, NULL);
@@ -903,6 +903,7 @@ eg_utf8_to_utf16_general (const gchar *str, glong len, glong *items_read, glong
g_set_error (err, G_CONVERT_ERROR, G_CONVERT_ERROR_FAILED, "Conversions with embedded nulls must pass the string length");
return NULL;
}
+
len = strlen (str);
}
@@ -910,29 +911,18 @@ eg_utf8_to_utf16_general (const gchar *str, glong len, glong *items_read, glong
inleft = len;
while (inleft > 0) {
- if ((n = decode_utf8 (inptr, inleft, &c)) < 0) {
- if (errno == EILSEQ) {
- g_set_error (err, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE,
- "Illegal byte sequence encounted in the input.");
- } else if (items_read) {
- /* partial input is ok if we can let our caller know... */
- break;
- } else {
- g_set_error (err, G_CONVERT_ERROR, G_CONVERT_ERROR_PARTIAL_INPUT,
- "Partial byte sequence encountered in the input.");
- }
-
- if (items_read)
- *items_read = inptr - str;
-
- if (items_written)
- *items_written = 0;
-
- return NULL;
- } else if (c == 0 && !include_nuls)
+ if ((n = decode_utf8 (inptr, inleft, &c)) < 0)
+ goto error;
+
+ if (c == 0 && !include_nuls)
break;
- outlen += g_unichar_to_utf16 (c, NULL);
+ if ((u = g_unichar_to_utf16 (c, NULL)) < 0) {
+ errno = EILSEQ;
+ goto error;
+ }
+
+ outlen += u;
inleft -= n;
inptr += n;
}
@@ -950,7 +940,8 @@ eg_utf8_to_utf16_general (const gchar *str, glong len, glong *items_read, glong
while (inleft > 0) {
if ((n = decode_utf8 (inptr, inleft, &c)) < 0)
break;
- else if (c == 0 && !include_nuls)
+
+ if (c == 0 && !include_nuls)
break;
outptr += g_unichar_to_utf16 (c, outptr);
@@ -961,6 +952,26 @@ eg_utf8_to_utf16_general (const gchar *str, glong len, glong *items_read, glong
*outptr = '\0';
return outbuf;
+
+ error:
+ if (errno == EILSEQ) {
+ g_set_error (err, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE,
+ "Illegal byte sequence encounted in the input.");
+ } else if (items_read) {
+ /* partial input is ok if we can let our caller know... */
+ break;
+ } else {
+ g_set_error (err, G_CONVERT_ERROR, G_CONVERT_ERROR_PARTIAL_INPUT,
+ "Partial byte sequence encountered in the input.");
+ }
+
+ if (items_read)
+ *items_read = inptr - str;
+
+ if (items_written)
+ *items_written = 0;
+
+ return NULL;
}
gunichar2 *
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mono/packages/mono.git
More information about the Pkg-mono-svn-commits
mailing list