[dpdk-dev,4/5] cfgfile: use strnlen to constrain memchr search

Message ID 1488482971-170522-5-git-send-email-allain.legacy@windriver.com (mailing list archive)
State Superseded, archived
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Allain Legacy March 2, 2017, 7:29 p.m. UTC
  The call to memchr() uses the absolute length of the string buffer instead
of the actual length of the string returned by fgets().  This causes the
search to go beyond the '\n' character and find ';' characters in random
garbage on the stack.  This then causes the 'len' variable to be updated
and the subsequent search for the '=' character to potentially find one
beyond the first newline character.

Since this bug relies on ';' and '=' characters appearing in random places
in the 'buffer' variable it is intermittently reproducible at best.

Signed-off-by: Allain Legacy <allain.legacy@windriver.com>
---
 lib/librte_cfgfile/rte_cfgfile.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Patch

diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c
index 2aba169..28956ea 100644
--- a/lib/librte_cfgfile/rte_cfgfile.c
+++ b/lib/librte_cfgfile/rte_cfgfile.c
@@ -133,7 +133,8 @@  struct rte_cfgfile *
 					"Check if line too long\n", lineno);
 			goto error1;
 		}
-		pos = memchr(buffer, RTE_LIBRTE_CFGFILE_COMMENT_CHAR, len);
+		pos = memchr(buffer, RTE_LIBRTE_CFGFILE_COMMENT_CHAR,
+			     sizeof(buffer));
 		if (pos != NULL) {
 			*pos = '\0';
 			len = pos -  buffer;