Skip to content

Commit

Permalink
net/xfrm/xfrm_replay: avoid division by zero
Browse files Browse the repository at this point in the history
All of the xfrm_replay->advance functions in xfrm_replay.c check if
x->replay_esn->replay_window is zero (and return if so).  However,
one of them, xfrm_replay_advance_bmp(), divides by that value (in the
'%' operator) before doing the check, which can potentially trigger
a divide-by-zero exception.  Some compilers will also assume that the
earlier division means the value cannot be zero later, and thus will
eliminate the subsequent zero check as dead code.

This patch moves the division to after the check.

Signed-off-by: Nickolai Zeldovich <nickolai@csail.mit.edu>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
  • Loading branch information
Nickolai Zeldovich authored and Steffen Klassert committed Jan 18, 2013
1 parent a9403f8 commit e2f6725
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion net/xfrm/xfrm_replay.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,13 @@ static void xfrm_replay_advance_bmp(struct xfrm_state *x, __be32 net_seq)
u32 diff;
struct xfrm_replay_state_esn *replay_esn = x->replay_esn;
u32 seq = ntohl(net_seq);
u32 pos = (replay_esn->seq - 1) % replay_esn->replay_window;
u32 pos;

if (!replay_esn->replay_window)
return;

pos = (replay_esn->seq - 1) % replay_esn->replay_window;

if (seq > replay_esn->seq) {
diff = seq - replay_esn->seq;

Expand Down

0 comments on commit e2f6725

Please sign in to comment.