Subject: [PATCH] [IPV4]: Buffer overflow

From: Roel Kluin <[email-masked]>
Date: Wed, 29 Jul 2009 12:52:50 +0200

If arp_format_neigh_entry() can be called with n->dev->addr_len == 0, then a
write to hbuffer[-1] occurs.

Signed-off-by: Roel Kluin <[email-masked]>
---
Found with Parfait, http://research.sun.com/projects/parfait/

It's not clear whether this can happen or not.

diff --git a/net/ipv4/arp.c b/net/ipv4/arp.c
index c29d75d..252336f 100644
--- a/net/ipv4/arp.c
+++ b/net/ipv4/arp.c
@@ -1304,7 +1304,8 @@ static void arp_format_neigh_entry(struct seq_file *seq,
 		hbuffer[k++] = hex_asc_lo(n->ha[j]);
 		hbuffer[k++] = ':';
 	}
-	hbuffer[--k] = 0;
+	if (k != 0)
+		hbuffer[--k] = 0;
 #if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
 	}
 #endif