]> git.baikalelectronics.ru Git - kernel.git/commit
ipv4: avoid undefined behavior in do_ip_setsockopt()
authorXi Wang <xi.wang@gmail.com>
Sun, 11 Nov 2012 11:20:01 +0000 (11:20 +0000)
committerDavid S. Miller <davem@davemloft.net>
Sun, 11 Nov 2012 22:53:13 +0000 (17:53 -0500)
commit37e95dbeb774f0f3696046783c270c6804a554f0
tree86ac3ac72907079585afc43ec2a25edcb8bb051b
parente68bb186da76e0ca5a415527e86b8bb724bd13d1
ipv4: avoid undefined behavior in do_ip_setsockopt()

(1<<optname) is undefined behavior in C with a negative optname or
optname larger than 31.  In those cases the result of the shift is
not necessarily zero (e.g., on x86).

This patch simplifies the code with a switch statement on optname.
It also allows the compiler to generate better code (e.g., using a
64-bit mask).

Signed-off-by: Xi Wang <xi.wang@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv4/ip_sockglue.c