summaryrefslogtreecommitdiff
path: root/epan/wslua/wslua_tvb.c
diff options
context:
space:
mode:
authorCédric Delmas <cedricde@outlook.fr>2015-07-13 10:45:37 +0200
committerHadriel Kaplan <hadrielk@yahoo.com>2015-07-13 13:40:59 +0000
commitaf12e335093dc913cd9ec0e9efe5bceba071cfd1 (patch)
tree0f39ed3625aabee0fad4f65fe787710ba37b83e2 /epan/wslua/wslua_tvb.c
parent3a7890193554c954728f8898bb6083e3f29d85eb (diff)
downloadwireshark-af12e335093dc913cd9ec0e9efe5bceba071cfd1.tar.gz
Change Lua's tvbrange:*int64() to read only the number of bytes specified in
the range. Previously the length was ignored and 8 bytes were always read. The constraint on int64() and le_int64() becomes stricter to match int()'s ones: the range must be 1, 2, 4 or 8 octets long. Change-Id: Ic66798757564ac840c332b978effb418726a654c Reviewed-on: https://code.wireshark.org/review/9622 Petri-Dish: Hadriel Kaplan <hadrielk@yahoo.com> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Hadriel Kaplan <hadrielk@yahoo.com>
Diffstat (limited to 'epan/wslua/wslua_tvb.c')
-rw-r--r--epan/wslua/wslua_tvb.c64
1 files changed, 46 insertions, 18 deletions
diff --git a/epan/wslua/wslua_tvb.c b/epan/wslua/wslua_tvb.c
index e1d180442c..9e44ea6b51 100644
--- a/epan/wslua/wslua_tvb.c
+++ b/epan/wslua/wslua_tvb.c
@@ -498,16 +498,29 @@ WSLUA_METHOD TvbRange_uint64(lua_State* L) {
switch (tvbr->len) {
case 1:
+ pushUInt64(L,tvb_get_guint8(tvbr->tvb->ws_tvb,tvbr->offset));
+ return 1;
case 2:
+ pushUInt64(L,tvb_get_ntohs(tvbr->tvb->ws_tvb,tvbr->offset));
+ return 1;
case 3:
+ pushUInt64(L,tvb_get_ntoh24(tvbr->tvb->ws_tvb,tvbr->offset));
+ return 1;
case 4:
+ pushUInt64(L,tvb_get_ntohl(tvbr->tvb->ws_tvb,tvbr->offset));
+ return 1;
case 5:
+ pushUInt64(L,tvb_get_ntoh40(tvbr->tvb->ws_tvb,tvbr->offset));
+ return 1;
case 6:
+ pushUInt64(L,tvb_get_ntoh48(tvbr->tvb->ws_tvb,tvbr->offset));
+ return 1;
case 7:
- case 8: {
+ pushUInt64(L,tvb_get_ntoh56(tvbr->tvb->ws_tvb,tvbr->offset));
+ return 1;
+ case 8:
pushUInt64(L,tvb_get_ntoh64(tvbr->tvb->ws_tvb,tvbr->offset));
WSLUA_RETURN(1); /* The `UInt64` object. */
- }
default:
luaL_error(L,"TvbRange:uint64() does not handle %d byte integers",tvbr->len);
return 0;
@@ -529,16 +542,29 @@ WSLUA_METHOD TvbRange_le_uint64(lua_State* L) {
switch (tvbr->len) {
case 1:
+ pushUInt64(L,tvb_get_guint8(tvbr->tvb->ws_tvb,tvbr->offset));
+ return 1;
case 2:
+ pushUInt64(L,tvb_get_letohs(tvbr->tvb->ws_tvb,tvbr->offset));
+ return 1;
case 3:
+ pushUInt64(L,tvb_get_letoh24(tvbr->tvb->ws_tvb,tvbr->offset));
+ return 1;
case 4:
+ pushUInt64(L,tvb_get_letohl(tvbr->tvb->ws_tvb,tvbr->offset));
+ return 1;
case 5:
+ pushUInt64(L,tvb_get_letoh40(tvbr->tvb->ws_tvb,tvbr->offset));
+ return 1;
case 6:
+ pushUInt64(L,tvb_get_letoh48(tvbr->tvb->ws_tvb,tvbr->offset));
+ return 1;
case 7:
- case 8: {
+ pushUInt64(L,tvb_get_letoh56(tvbr->tvb->ws_tvb,tvbr->offset));
+ return 1;
+ case 8:
pushUInt64(L,tvb_get_letoh64(tvbr->tvb->ws_tvb,tvbr->offset));
WSLUA_RETURN(1); /* The `UInt64` object. */
- }
default:
luaL_error(L,"TvbRange:le_uint64() does not handle %d byte integers",tvbr->len);
return 0;
@@ -615,7 +641,7 @@ WSLUA_METHOD TvbRange_le_int(lua_State* L) {
*/
WSLUA_METHOD TvbRange_int64(lua_State* L) {
/* Get a Big Endian (network order) signed 64 bit integer from a `TvbRange`, as an `Int64` object.
- The range must be 1-8 octets long. */
+ The range must be 1, 2, 4 or 8 octets long. */
TvbRange tvbr = checkTvbRange(L,1);
if (!(tvbr && tvbr->tvb)) return 0;
if (tvbr->tvb->expired) {
@@ -625,16 +651,17 @@ WSLUA_METHOD TvbRange_int64(lua_State* L) {
switch (tvbr->len) {
case 1:
+ pushInt64(L,(gint8)tvb_get_guint8(tvbr->tvb->ws_tvb,tvbr->offset));
+ return 1;
case 2:
- case 3:
+ pushInt64(L,(gint16)tvb_get_ntohs(tvbr->tvb->ws_tvb,tvbr->offset));
+ return 1;
case 4:
- case 5:
- case 6:
- case 7:
- case 8: {
+ pushInt64(L,(gint32)tvb_get_ntohl(tvbr->tvb->ws_tvb,tvbr->offset));
+ return 1;
+ case 8:
pushInt64(L,(gint64)tvb_get_ntoh64(tvbr->tvb->ws_tvb,tvbr->offset));
WSLUA_RETURN(1); /* The `Int64` object. */
- }
default:
luaL_error(L,"TvbRange:int64() does not handle %d byte integers",tvbr->len);
return 0;
@@ -646,7 +673,7 @@ WSLUA_METHOD TvbRange_int64(lua_State* L) {
*/
WSLUA_METHOD TvbRange_le_int64(lua_State* L) {
/* Get a Little Endian signed 64 bit integer from a `TvbRange`, as an `Int64` object.
- The range must be 1-8 octets long. */
+ The range must be 1, 2, 4 or 8 octets long. */
TvbRange tvbr = checkTvbRange(L,1);
if (!(tvbr && tvbr->tvb)) return 0;
if (tvbr->tvb->expired) {
@@ -656,16 +683,17 @@ WSLUA_METHOD TvbRange_le_int64(lua_State* L) {
switch (tvbr->len) {
case 1:
+ pushInt64(L,(gint8)tvb_get_guint8(tvbr->tvb->ws_tvb,tvbr->offset));
+ return 1;
case 2:
- case 3:
+ pushInt64(L,(gint16)tvb_get_letohs(tvbr->tvb->ws_tvb,tvbr->offset));
+ return 1;
case 4:
- case 5:
- case 6:
- case 7:
- case 8: {
+ pushInt64(L,(gint32)tvb_get_letohl(tvbr->tvb->ws_tvb,tvbr->offset));
+ return 1;
+ case 8:
pushInt64(L,(gint64)tvb_get_letoh64(tvbr->tvb->ws_tvb,tvbr->offset));
WSLUA_RETURN(1); /* The `Int64` object. */
- }
default:
luaL_error(L,"TvbRange:le_int64() does not handle %d byte integers",tvbr->len);
return 0;