diff options
author | Jakub Zawadzki <darkjames-ws@darkjames.pl> | 2014-01-07 22:17:32 +0000 |
---|---|---|
committer | Jakub Zawadzki <darkjames-ws@darkjames.pl> | 2014-01-07 22:17:32 +0000 |
commit | abda30e9e6d8fd9aa28edc4677796e61a9c88997 (patch) | |
tree | ab90b4994f29142a1554c36b6160033b3d499405 /wsutil/unicode-utils.c | |
parent | d1dcee936b2a0ed257c526889b664e2b314d3eb0 (diff) |
Fix bug #9618: Invalid utf8 causes JSON dissector assertion failure "g_utf8_validate"
Validate JSON UTF-8 characters, replace with '?' when invalid.
svn path=/trunk/; revision=54633
Diffstat (limited to 'wsutil/unicode-utils.c')
-rw-r--r-- | wsutil/unicode-utils.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/wsutil/unicode-utils.c b/wsutil/unicode-utils.c index 8935e46f38..21cc489df7 100644 --- a/wsutil/unicode-utils.c +++ b/wsutil/unicode-utils.c @@ -22,12 +22,23 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#ifndef _WIN32 -#error "This is only for Windows" -#endif - #include "unicode-utils.h" +int +ws_utf8_char_len(guint8 ch) +{ + if (ch >= 0xfe) return -1; + if (ch >= 0xfc) return 6; + if (ch >= 0xf8) return 5; + if (ch >= 0xf0) return 4; + if (ch >= 0xe0) return 3; + if (ch >= 0xc0) return 2; + else return 1; +} + + +#ifdef _WIN32 + #include <shellapi.h> /** @file @@ -157,3 +168,5 @@ arg_list_utf_16to8(int argc, char *argv[]) { } } /* XXX else bail because something is horribly, horribly wrong? */ } + +#endif |