isotpsniffer: only invoke LL_OPTS setsockopt when set on commandline

In commit da33f96edf ("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: da33f96edf ("isotpsniffer: Add support for llopts")
Reported by: https://github.com/ikuyas
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
pull/102/merge v2020.02.04
Oliver Hartkopp 2020-02-04 17:28:11 +01:00
parent ae69062657
commit da65fdfe0d
1 changed files with 1 additions and 1 deletions

View File

@ -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;