From: Olivier Matz Date: Wed, 29 Apr 2020 09:38:59 +0000 (+0200) Subject: kvargs: fix crash when parsing an invalid token on freebsd X-Git-Url: http://git.droids-corp.org/?p=dpdk.git;a=commitdiff_plain;h=ea84b3ebe0def34a5a1e3a81dd13375bd37d4c4b kvargs: fix crash when parsing an invalid token on freebsd The behavior of strtok_r() is not the same between GNU libc and FreeBSD libc: in the first case, the context is set to "" when the last token is returned, while in the second case it is set to NULL. On FreeBSD, the current code crashes because we are dereferencing a NULL pointer (ctx1). Fix it by first checking if it is NULL. This works with both GNU and FreeBSD libc. Fixes: ffcf831454a9 ("kvargs: fix buffer overflow when parsing list") Signed-off-by: Olivier Matz --- diff --git a/lib/librte_kvargs/rte_kvargs.c b/lib/librte_kvargs/rte_kvargs.c index 1d815dcd96..285081c86c 100644 --- a/lib/librte_kvargs/rte_kvargs.c +++ b/lib/librte_kvargs/rte_kvargs.c @@ -50,7 +50,7 @@ rte_kvargs_tokenize(struct rte_kvargs *kvlist, const char *params) /* Find the end of the list. */ while (str[strlen(str) - 1] != ']') { /* Restore the comma erased by strtok_r(). */ - if (ctx1[0] == '\0') + if (ctx1 == NULL || ctx1[0] == '\0') return -1; /* no closing bracket */ str[strlen(str)] = ','; /* Parse until next comma. */