From 74e0d3a17461fadda1987baab775f7068e3732b1 Mon Sep 17 00:00:00 2001 From: Jacek Piasecki Date: Thu, 26 Oct 2017 08:24:06 +0200 Subject: [PATCH] cfgfile: fix null pointer dereference in parsing Function memchr() could return NULL and assign it to split[1] pointer. Additional check and error handing is made after memchr() call. Coverity issue: 195004 Fixes: a6a47ac9c2c9 ("cfgfile: rework load function") Signed-off-by: Jacek Piasecki Acked-by: Michal Jastrzebski --- lib/librte_cfgfile/rte_cfgfile.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c index 124aef5848..80077b6448 100644 --- a/lib/librte_cfgfile/rte_cfgfile.c +++ b/lib/librte_cfgfile/rte_cfgfile.c @@ -241,6 +241,11 @@ rte_cfgfile_load_with_params(const char *filename, int flags, split[0] = buffer; split[1] = memchr(buffer, '=', len); + if (split[1] == NULL) { + printf("Error line %d - no '='" + "character found\n", lineno); + goto error1; + } *split[1] = '\0'; split[1]++; @@ -268,7 +273,7 @@ rte_cfgfile_load_with_params(const char *filename, int flags, goto error1; _add_entry(&cfg->sections[cfg->num_sections - 1], - split[0], (split[1] ? split[1] : "")); + split[0], split[1]); } } fclose(f); -- 2.20.1