summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Huus <eapache@gmail.com>2012-07-28 15:51:37 +0000
committerEvan Huus <eapache@gmail.com>2012-07-28 15:51:37 +0000
commit1457a01f492621360a0caf07d6eba3777ae1b1e6 (patch)
tree853587e81f72b8ca22c70274d1df5c8c019d0774
parent98bbc5a3d96647170a5c9f01a8a16b6405febe7b (diff)
downloadwireshark-1457a01f492621360a0caf07d6eba3777ae1b1e6.tar.gz
Always memset the packet-header struct in Lua to avoid
crashes from garbage data. Also, give Lua a copy of the packet comment if there is one. Fixes: https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=7538 svn path=/trunk/; revision=44093
-rw-r--r--epan/wslua/wslua_dumper.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/epan/wslua/wslua_dumper.c b/epan/wslua/wslua_dumper.c
index f2b3077513..786d247226 100644
--- a/epan/wslua/wslua_dumper.c
+++ b/epan/wslua/wslua_dumper.c
@@ -291,13 +291,18 @@ WSLUA_METHOD Dumper_dump(lua_State* L) {
if (! ba) WSLUA_ARG_ERROR(Dumper_dump,BYTEARRAY,"must be a ByteArray");
- pkthdr.ts.secs = (unsigned)floor(ts);
+ memset(&pkthdr, 0, sizeof(pkthdr));
+
+ pkthdr.ts.secs = (unsigned)floor(ts);
pkthdr.ts.nsecs = (unsigned)floor((ts - (double)pkthdr.ts.secs) * 1000000000);
- pkthdr.len = ba->len;
- pkthdr.caplen = ba->len;
+ pkthdr.len = ba->len;
+ pkthdr.caplen = ba->len;
pkthdr.pkt_encap = DUMPER_ENCAP(d);
+ /* TODO: Can we get access to pinfo->fd->opt_comment here somehow? We
+ * should be copying it to pkthdr.opt_comment if we can. */
+
if (! wtap_dump(d, &pkthdr, ph->wph, ba->data, &err)) {
luaL_error(L,"error while dumping: %s",
wtap_strerror(err));
@@ -370,12 +375,17 @@ WSLUA_METHOD Dumper_dump_current(lua_State* L) {
tvb = data_src->tvb;
- pkthdr.ts.secs = lua_pinfo->fd->abs_ts.secs;
- pkthdr.ts.nsecs = lua_pinfo->fd->abs_ts.nsecs;
- pkthdr.len = tvb_reported_length(tvb);
- pkthdr.caplen = tvb_length(tvb);
+ memset(&pkthdr, 0, sizeof(pkthdr));
+
+ pkthdr.ts.secs = lua_pinfo->fd->abs_ts.secs;
+ pkthdr.ts.nsecs = lua_pinfo->fd->abs_ts.nsecs;
+ pkthdr.len = tvb_reported_length(tvb);
+ pkthdr.caplen = tvb_length(tvb);
pkthdr.pkt_encap = lua_pinfo->fd->lnk_t;
+ if (lua_pinfo->fd->opt_comment)
+ pkthdr.opt_comment = ep_strdup(lua_pinfo->fd->opt_comment);
+
data = ep_tvb_memdup(tvb,0,pkthdr.caplen);
if (! wtap_dump(d, &pkthdr, lua_pinfo->pseudo_header, data, &err)) {