kvargs: fix crash when parsing an invalid token on freebsd kvargs2
authorOlivier Matz <olivier.matz@6wind.com>
Wed, 29 Apr 2020 09:38:59 +0000 (11:38 +0200)
committerOlivier Matz <olivier.matz@6wind.com>
Wed, 29 Apr 2020 09:38:59 +0000 (11:38 +0200)
commitea84b3ebe0def34a5a1e3a81dd13375bd37d4c4b
tree1748cdcaf19c7b57d5b0631db2de79ce95abe12c
parent37924a2f078615c5bdac226a90cd63f686f9e7b1
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 <olivier.matz@6wind.com>
lib/librte_kvargs/rte_kvargs.c