diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2013-06-13 15:52:01 +0200 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2013-06-13 15:52:01 +0200 |
commit | ffc485dbcab01699fdbe8d9cf3da6a3f2bbed698 (patch) | |
tree | 820d5f6b16636375b76d79236b2e96d930b699f0 /dissector_eth.c | |
parent | b6cb72afcf877e6b1ac062ca17e0be01c963cce7 (diff) |
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 <tklauser@distanz.ch>
Diffstat (limited to 'dissector_eth.c')
-rw-r--r-- | dissector_eth.c | 15 |
1 files changed, 11 insertions, 4 deletions
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, ' '); |