Skip to contentSkip to conversation

ceph: fix overflow check in build_snap_context()

PATCH New Alex Elder 1 participant 1 message Feb 29, 2012 Ceph client

lore
Share & tools
lore

Alex Elder

author
#0 lore raw

PATCH 1/1 ceph: fix overflow check in build_snap_context()

The overflow check for a + n * b should be (n > (ULONG_MAX - a) / b), rather than (n > ULONG_MAX / b - a).

---
 fs/ceph/snap.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
fs/ceph/snap.c +1 -1
index a559c80..f04c096 100644
@@ -331,7 +331,7 @@ static int build_snap_context(struct ceph_snap_realm *realm)
 
 	/* alloc new snap context */
 	err = -ENOMEM;
-	if (num > ULONG_MAX / sizeof(u64) - sizeof(*snapc))
+	if (num > (ULONG_MAX - sizeof(*snapc)) / sizeof(u64))
 		goto fail;
 	snapc = kzalloc(sizeof(*snapc) + num*sizeof(u64), GFP_NOFS);
 	if (!snapc)
Signature · 1 line
1.7.5.4