From bdb9efef8991396b6c77e669a140965c91bb8558 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Mon, 10 Jun 2013 23:53:28 +0200 Subject: oui: Make parsing of oui.conf more robust In the unlikely case of the oui.conf file not conforming to the required format (e.g. by the user supplying one by himself), we would end up - in the worst case dereferencing a null pointer, if the condiition (ptr = strstr(buff, ", ")) is false. Thus make the entire parsing a bit more robust and just ignore lines not following the required format. The null pointer dereference was found by the Coverity scanner. Signed-off-by: Tobias Klauser --- oui.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'oui.c') diff --git a/oui.c b/oui.c index 3354ed4..2f6ec72 100644 --- a/oui.c +++ b/oui.c @@ -36,7 +36,7 @@ const char *lookup_vendor(unsigned int id) void dissector_init_oui(void) { FILE *fp; - char buff[128], *ptr; + char buff[128], *ptr, *end; struct vendor_id *v; void **pos; @@ -54,10 +54,16 @@ void dissector_init_oui(void) ptr = buff; v = xmalloc(sizeof(*v)); - v->id = strtol(ptr, &ptr, 0); + v->id = strtol(ptr, &end, 0); + /* No valid line, skip */ + if (v->id == 0 && end == ptr) + continue; - if ((ptr = strstr(buff, ", "))) - ptr += strlen(", "); + ptr = strstr(buff, ", "); + if (!ptr) + continue; + + ptr += strlen(", "); ptr = strtrim_right(ptr, '\n'); ptr = strtrim_right(ptr, ' '); -- cgit v1.2.3-54-g00ecf