From da65fdfe0d1986625ee00af0b56ae17ec132e700 Mon Sep 17 00:00:00 2001 From: Oliver Hartkopp Date: Tue, 4 Feb 2020 17:28:11 +0100 Subject: [PATCH] isotpsniffer: only invoke LL_OPTS setsockopt when set on commandline In commit da33f96edfb9 ("isotpsniffer: Add support for llopts") the setsockopt() syscall for the link layer options CAN_ISOTP_LL_OPTS has been added. Unfortunately the syscall has been invoked even if there were no values given on the command line and 'zero values' have been passed to the kernel which correctly answered with -EINVAL. And a missing check for a mandatory non-zero value for the MTU. Fixes: da33f96edfb9 ("isotpsniffer: Add support for llopts") Reported by: https://github.com/ikuyas Signed-off-by: Oliver Hartkopp --- isotpsniffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/isotpsniffer.c b/isotpsniffer.c index 1bb4489..6f053c8 100644 --- a/isotpsniffer.c +++ b/isotpsniffer.c @@ -322,7 +322,7 @@ int main(int argc, char **argv) goto out; } - if ((setsockopt(t, SOL_CAN_ISOTP, CAN_ISOTP_LL_OPTS, &llopts, sizeof(llopts))) < 0) { + if ((llopts.mtu) && (setsockopt(t, SOL_CAN_ISOTP, CAN_ISOTP_LL_OPTS, &llopts, sizeof(llopts))) < 0) { perror("setsockopt"); r = 1; goto out;