From 7694a8659d46ce3483b745779baeccdf0a8c47fe Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Fri, 18 Nov 2011 21:39:18 +0000 Subject: Fail if somebody tries to write out a packet with an unsupported encapsulation. svn path=/trunk/; revision=39944 --- wiretap/k12text.l | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'wiretap/k12text.l') diff --git a/wiretap/k12text.l b/wiretap/k12text.l index 541441556a..fae1d62350 100644 --- a/wiretap/k12text.l +++ b/wiretap/k12text.l @@ -337,7 +337,6 @@ static const struct { int e; const char* s; } encaps[] = { { WTAP_ENCAP_MTP3, "SSCF" }, { WTAP_ENCAP_CHDLC, "HDLC" }, /* ... */ - { WTAP_ENCAP_UNKNOWN, "UNKNOWN" }, { 0, NULL } }; @@ -350,23 +349,33 @@ k12text_dump(wtap_dumper *wdh _U_, const struct wtap_pkthdr *phdr, size_t left = K12BUF_SIZE; gint wl; char *p; - const char* str_enc = ""; + const char* str_enc; guint i; guint ns; guint ms; gboolean ret; + str_enc = NULL; + for(i=0; encaps[i].s; i++) { + if (phdr->pkt_encap == encaps[i].e) { + str_enc = encaps[i].s; + break; + } + } + if (str_enc == NULL) { + /* + * That encapsulation type is not supported. Fail. + */ + *err = WTAP_ERR_UNSUPPORTED_ENCAP; + return FALSE; + } + buf = g_malloc(K12BUF_SIZE); p = buf; ms = phdr->ts.nsecs / 1000000; ns = (phdr->ts.nsecs - (1000000*ms))/1000; - for(i=0; encaps[i].s; i++) { - str_enc = encaps[i].s; - if (phdr->pkt_encap == encaps[i].e) break; - } - #ifdef _MSC_VER /* calling gmtime() on MSVC 2005 with huge values causes it to crash */ /* XXX - find the exact value that still does work */ -- cgit v1.2.1