提交 aaf473d0 编写于 作者: N Norbert Slusarek 提交者: Marc Kleine-Budde

can: j1939: j1939_sk_setsockopt(): prevent allocation of j1939 filter for optlen == 0

If optval != NULL and optlen == 0 are specified for SO_J1939_FILTER in
j1939_sk_setsockopt(), memdup_sockptr() will return ZERO_PTR for 0
size allocation. The new filter will be mistakenly assigned ZERO_PTR.
This patch checks for optlen != 0 and filter will be assigned NULL in
case of optlen == 0.

Fixes: 9d71dd0c ("can: add support of SAE J1939 protocol")
Link: https://lore.kernel.org/r/20210620123842.117975-1-nslusarek@gmx.netSigned-off-by: NNorbert Slusarek <nslusarek@gmx.net>
Acked-by: NOleksij Rempel <o.rempel@pengutronix.de>
Signed-off-by: NMarc Kleine-Budde <mkl@pengutronix.de>
上级 c2f5c57d
......@@ -676,7 +676,7 @@ static int j1939_sk_setsockopt(struct socket *sock, int level, int optname,
switch (optname) {
case SO_J1939_FILTER:
if (!sockptr_is_null(optval)) {
if (!sockptr_is_null(optval) && optlen != 0) {
struct j1939_filter *f;
int c;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册