Re: Bug in IP accounting explained

Marc (marcl@magic.metawire.com)
Mon, 2 Jun 1997 10:39:44 -0700 (PDT)


> There's an easy cheesy fix, which is just to make all of the sprintf()
> format conversions have a fixed width, so that the converted length
> can't change between calls. The right way to fix it would be to make
> all the returned lines the same length, then divide the offset by the
> length to calculate how many list nodes to skip over before starting the
> new conversion.

That was the approach that Janos Farkas and Alan Cox have independently
taken to fix the bug after I made my report to the list.

Here is a portion of what Janos sent me (and what Alan confirmed):

--- snip ---
And to check it, simply test this patch, and report to the usual
channels if it solves your problems. :) It's not the right one
however, as other fields could get longer, the more proper is
probably to have some kind of locking while reading the proc
entries, but it should be good to check my theory.

--- ip_fw.c.orig Thu May 29 10:01:39 1997
+++ ip_fw.c Thu May 29 11:01:42 1997
@@ -1120,7 +1120,7 @@ static int ip_chain_procinfo(int stage,
ntohl(i->fw_dst.s_addr),ntohl(i->fw_dmsk.s_addr),
(i->fw_vianame)[0] ? i->fw_vianame : "-",
ntohl(i->fw_via.s_addr),i->fw_flg);
- len+=sprintf(buffer+len,"%u %u %-9lu %-9lu",
+ len+=sprintf(buffer+len,"%u %u %-10lu %-10lu",
i->fw_nsp,i->fw_ndp, i->fw_pcnt,i->fw_bcnt);
for (p = 0; p < IP_FW_MAX_PORTS; p++)
len+=sprintf(buffer+len, " %u", i->fw_pts[p]);
--- snip ---

I've been running that patch on the machine where I had problems, and even
if all the potential problems are not gone, mine at least are.

Marc