Skip to contentSkip to conversation

SUNRPC: off by one in BUG_ON()

PATCH In review Dan Carpenter 2 participants 2 messages Oct 29, 2014

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 SUNRPC: off by one in BUG_ON()

The m->pool_to[] array has "maxpools" number of elements. It's allocated in svc_pool_map_alloc_arrays() which we called earlier in the function. This test should be >= instead of >.

---
This is very old code, but hopefully the off by one doesn't affect runtime.

net/sunrpc/svc.c +1 -1
index ca8a795..349c98f 100644
@@ -189,7 +189,7 @@ svc_pool_map_init_percpu(struct svc_pool_map *m)
 		return err;
 
 	for_each_online_cpu(cpu) {
-		BUG_ON(pidx > maxpools);
+		BUG_ON(pidx >= maxpools);
 		m->to_pool[cpu] = pidx;
 		m->pool_to[pidx] = cpu;
 		pidx++;
#1 lore raw
Quoted 8 lines · Dan Carpenter

The m->pool_to[] array has "maxpools" number of elements. It's allocated in svc_pool_map_alloc_arrays() which we called earlier in the function. This test should be >= instead of >.

---
This is very old code, but hopefully the off by one doesn't affect runtime.

Yeah, doesn't look like a big deal, but thanks, applying for 3.19.--b.

Quoted 14 lines
net/sunrpc/svc.c +1 -1
index ca8a795..349c98f 100644
@@ -189,7 +189,7 @@ svc_pool_map_init_percpu(struct svc_pool_map *m)
 		return err;
 
 	for_each_online_cpu(cpu) {
-		BUG_ON(pidx > maxpools);
+		BUG_ON(pidx >= maxpools);
 		m->to_pool[cpu] = pidx;
 		m->pool_to[pidx] = cpu;
 		pidx++;