From ffc485dbcab01699fdbe8d9cf3da6a3f2bbed698 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Thu, 13 Jun 2013 15:52:01 +0200 Subject: dissector: eth: Make port file parsing more robust Follow commit bdb9efef ("oui: Make parsing of oui.conf more robust") and make parsing the upd.conf, tcp.conf and ether.conf files more robust against format flaws. ALso here, in the worst case, we would end up dereferencing a null pointer. The null pointer dereference was found by the Coverity scanner. Signed-off-by: Tobias Klauser --- dissector_eth.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'dissector_eth.c') diff --git a/dissector_eth.c b/dissector_eth.c index b8166e4..5a06906 100644 --- a/dissector_eth.c +++ b/dissector_eth.c @@ -112,7 +112,7 @@ enum ports { static void dissector_init_ports(enum ports which) { FILE *fp; - char buff[128], *ptr, *file; + char buff[128], *ptr, *file, *end; struct hash_table *table; struct port *p; void **pos; @@ -145,10 +145,17 @@ static void dissector_init_ports(enum ports which) ptr = buff; p = xmalloc(sizeof(*p)); - p->id = strtol(ptr, &ptr, 0); + p->id = strtol(ptr, &end, 0); + /* not a valid line, skip */ + if (p->id == 0 && end == ptr) + continue; - if ((ptr = strstr(buff, ", "))) - ptr += strlen(", "); + ptr = strstr(buff, ", "); + /* likewise */ + if (!ptr) + continue; + + ptr += strlen(", "); ptr = strtrim_right(ptr, '\n'); ptr = strtrim_right(ptr, ' '); -- cgit v1.2.3-54-g00ecf