nfsd: avoid undefined signed overflow
authorJim Rees <rees@umich.edu>
Fri, 17 May 2013 21:33:00 +0000 (17:33 -0400)
committerJ. Bruce Fields <bfields@redhat.com>
Tue, 21 May 2013 15:02:03 +0000 (11:02 -0400)
In C, signed integer overflow results in undefined behavior, but unsigned
overflow wraps around. So do the subtraction first, then cast to signed.

Reported-by: Joakim Tjernlund <joakim.tjernlund@transmode.se>
Signed-off-by: Jim Rees <rees@umich.edu>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
fs/nfsd/nfs4state.c

index 91ead0ed9f11b7dd6e10fdfc3dfba66ef554be73..72f0c4e9a942b76a5af094c4d6aa4ea2125a0062 100644 (file)
@@ -3427,7 +3427,7 @@ grace_disallows_io(struct net *net, struct inode *inode)
 /* Returns true iff a is later than b: */
 static bool stateid_generation_after(stateid_t *a, stateid_t *b)
 {
-       return (s32)a->si_generation - (s32)b->si_generation > 0;
+       return (s32)(a->si_generation - b->si_generation) > 0;
 }
 
 static __be32 check_stateid_generation(stateid_t *in, stateid_t *ref, bool has_session)
This page took 0.027382 seconds and 5 git commands to generate.