Lua: check sscanf return value

Wslua's Int64.fromhex() and UInt64.fromhex() need to check the sscanf return
value. Found by coverity (CID 1191368 &1191369).

Change-Id: I67fba027e18341d429787515f94c794573dc41c2
Reviewed-on: https://code.wireshark.org/review/10183
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
This commit is contained in:
Hadriel Kaplan 2015-08-21 11:59:34 -04:00 committed by Alexis La Goutte
parent dd2a2d432a
commit d32c3dab46
1 changed files with 6 additions and 2 deletions

View File

@ -256,7 +256,9 @@ WSLUA_CONSTRUCTOR Int64_fromhex(lua_State* L) {
const gchar *s = luaL_checklstring(L,WSLUA_ARG_Int64_fromhex_HEX,&len);
if (len > 0) {
sscanf(s, "%" G_GINT64_MODIFIER "x", &result);
if (sscanf(s, "%" G_GINT64_MODIFIER "x", &result) != 1) {
return luaL_error(L, "Error decoding the passed-in hex string");
}
}
pushInt64(L,(gint64)result);
WSLUA_RETURN(1); /* The new `Int64` object. */
@ -816,7 +818,9 @@ WSLUA_CONSTRUCTOR UInt64_fromhex(lua_State* L) {
const gchar *s = luaL_checklstring(L,WSLUA_ARG_UInt64_fromhex_HEX,&len);
if (len > 0) {
sscanf(s, "%" G_GINT64_MODIFIER "x", &result);
if (sscanf(s, "%" G_GINT64_MODIFIER "x", &result) != 1) {
return luaL_error(L, "Error decoding the passed-in hex string");
}
}
pushUInt64(L,result);
WSLUA_RETURN(1); /* The new `UInt64` object. */