diff options
author | Paul Aurich <paul@darkrain42.org> | 2011-05-22 16:14:10 -0700 |
---|---|---|
committer | Paul Aurich <paul@darkrain42.org> | 2011-05-22 16:14:10 -0700 |
commit | 544b19989df4fac1a95af676c7da45d8e17c1263 (patch) | |
tree | e58bdc31a3a51f1ce1596d421f0af7584a45ba46 /util-src/encodings.c | |
parent | 6499dc4b3b441d35cc07f09c88ec5bc37be0d64f (diff) | |
download | prosody-544b19989df4fac1a95af676c7da45d8e17c1263.tar.gz prosody-544b19989df4fac1a95af676c7da45d8e17c1263.zip |
util.encodings: Check return values before proceeding
Diffstat (limited to 'util-src/encodings.c')
-rw-r--r-- | util-src/encodings.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/util-src/encodings.c b/util-src/encodings.c index e00f0091..9b6c6cf4 100644 --- a/util-src/encodings.c +++ b/util-src/encodings.c @@ -145,13 +145,17 @@ static int icu_stringprep_prep(lua_State *L, const UStringPrepProfile *profile) return 1; } u_strFromUTF8(unprepped, 1024, &unprepped_len, input, input_len, &err); + if (U_FAILURE(err)) { + luah_pushnil(L); + return 1; + } prepped_len = usprep_prepare(profile, unprepped, unprepped_len, prepped, 1024, 0, NULL, &err); if (U_FAILURE(err)) { lua_pushnil(L); return 1; } else { u_strToUTF8(output, 1024, &output_len, prepped, prepped_len, &err); - if(output_len < 1024) + if (U_SUCCESS(err) && output_len < 1024) lua_pushlstring(L, output, output_len); else lua_pushnil(L); @@ -258,13 +262,18 @@ static int Lidna_to_ascii(lua_State *L) /** idna.to_ascii(s) */ char output[1024]; u_strFromUTF8(ustr, 1024, &ulen, s, len, &err); + if (U_FAILURE(err)) { + lua_pushnil(L); + return 1; + } + dest_len = uidna_IDNToASCII(ustr, ulen, dest, 1024, UIDNA_USE_STD3_RULES, NULL, &err); if (U_FAILURE(err)) { lua_pushnil(L); return 1; } else { u_strToUTF8(output, 1024, &output_len, dest, dest_len, &err); - if(output_len < 1024) + if (U_SUCCESS(err) && output_len < 1024) lua_pushlstring(L, output, output_len); else lua_pushnil(L); @@ -283,13 +292,18 @@ static int Lidna_to_unicode(lua_State *L) /** idna.to_unicode(s) */ char output[1024]; u_strFromUTF8(ustr, 1024, &ulen, s, len, &err); + if (U_FAILURE(err)) { + lua_pushnil(L); + return 1; + } + dest_len = uidna_IDNToUnicode(ustr, ulen, dest, 1024, UIDNA_USE_STD3_RULES, NULL, &err); if (U_FAILURE(err)) { lua_pushnil(L); return 1; } else { u_strToUTF8(output, 1024, &output_len, dest, dest_len, &err); - if(output_len < 1024) + if (U_SUCCESS(err) && output_len < 1024) lua_pushlstring(L, output, output_len); else lua_pushnil(L); |