can: raw: use temp variable instead of rolling back config
Subsystems (2)
Oliver Hartkopp
maintainerIntroduce a temporary variable to check for an invalid configuration attempt from user space. Before this patch the value was copied to the real config variable and rolled back in the case of an error.
Suggested-by Marc Kleine-Budde <[email protected]>
Signed-off-by Oliver Hartkopp <[email protected]>
--- net/can/raw.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
net/can/raw.c +6 -5
@@ -521,10 +521,11 @@ static int raw_setsockopt(struct socket *sock, int level, int optname,struct raw_sock *ro =raw_sk (sk);struct can_filter *filter =NULL ;/* dyn. alloc'ed filters */ struct can_filter sfilter;/* single filter */ struct net_device *dev =NULL ;can_err_mask_t err_mask =0 ; +int fd_frames;int count =0 ;int err =0 ;if (level !=SOL_CAN_RAW )return -EINVAL ;
@@ -662,21 +663,21 @@ static int raw_setsockopt(struct socket *sock, int level, int optname,return -EFAULT ;break ;case CAN_RAW_FD_FRAMES : -if (optlen !=sizeof (ro->fd_frames)) +if (optlen !=sizeof (fd_frames))return -EINVAL ; -if (copy_from_sockptr (&ro->fd_frames, optval, optlen)) +if (copy_from_sockptr (&fd_frames, optval, optlen))return -EFAULT ;/* Enabling CAN XL includes CAN FD */ -if (ro->xl_frames && !ro->fd_frames) { - ro->fd_frames = ro->xl_frames; +if (ro->xl_frames && !fd_frames)return -EINVAL ; - } + + ro->fd_frames = fd_frames;break ;case CAN_RAW_XL_FRAMES :if (optlen !=sizeof (ro->xl_frames))return -EINVAL ;
Signature · 1 line
2.39.0