[Swan-dev] coverity warning in nic offload : shifting by negative amount has undefined behavior
Antony Antony
antony at phenome.org
Thu Aug 17 08:29:36 UTC 2017
Hi Ilan,
There is a coverity warning in the recently added nic-offload code. I do not
understand the related code completely to fix it myself.
Would you please take a look? and see if you can fix it.
programs/pluto/kernel_netlink.c:979 netlink_detect_offload
976
977 /* Feature is supported by kernel. Query device features */
978 blocks = (netlink_esp_hw_offload + 31) / 32;
CID 1452850 (#1 of 1): Bad bit shift operation (BAD_SHIFT)4.
negative_shift: In expression 1 << netlink_esp_hw_offload % 31, shifting by
a negative amount has undefined behavior. The shift amount,
netlink_esp_hw_offload % 31, is -2.
979 feature_bit = 1 << (netlink_esp_hw_offload % 31);
980
981 cmd = alloc_bytes(sizeof(*cmd) + sizeof(cmd->features[0]) *
blocks, "ethtool_gfeatures");
netlink_esp_hw_offload could be -1. I am not sure about -2?
when netlink_esp_hw_offload == -1i
netlink_esp_hw_offload % 31 = -1
1 << -1 is undefined. possiby bad things can happen. It is wort looking
into.
-antony
More information about the Swan-dev
mailing list