minor bug in iptables 1.2.9
Hi,
while reading the iptables 1.2.9 source, I found this small bug in iptables.c line 276:
struct in_addr *dotted_to_addr(const char *dotted)
{
char buf[20];
...
/* copy dotted string, because we need to modify it */
strncpy(buf, dotted, sizeof(buf) - 1);
...strncpy does not \0-terminate strings if strlen(src) == n, thus the following loop can easily run over the end of buf, if a big enough mask is given:
iptables -A INPUT -p tcp -s 1.1.1.1/000000000000000000.
Attached is a patch to fix this problem.
Karsten
iptables.c renamed from iptables~.c +1 -0
@@ -274,6 +274,7 @@/* copy dotted string, because we need to modify it */ strncpy (buf, dotted,sizeof (buf) -1 ); + buf[sizeof (buf) -1 ] ='\0' ; addrp = (unsigned char *) &(addr.s_addr); p = buf;
Martin Josefsson
AppliedQuoted 6 lines · Karsten Desler
strncpy does not \0-terminate strings if strlen(src) == n, thus the following loop can easily run over the end of buf, if a big enough mask is given:
iptables -A INPUT -p tcp -s 1.1.1.1/000000000000000000.Attached is a patch to fix this problem.
Applied, thanks
Signature · 1 line
/Martin
Hi,
today I had a little more time to look at the code. A few lines down, there's another incarnation of the same bug. line 641:
char buf[256];
...
strncpy(buf, name, sizeof(buf) - 1);
if ((p = strrchr(buf, '/')) != NULL) {
...Patch attached.
Karsten
iptables.c renamed from iptables~.c +1 -0
@@ -639,6 +640,7 @@int i, j, k, n;strncpy (buf, name,sizeof (buf) -1 ); + buf[sizeof (buf) -1 ] ='\0' ;if ((p =strrchr (buf,'/' )) !=NULL ) { *p ='\0' ; addrp =parse_mask (p +1 );
Martin Josefsson
AppliedQuoted 4 lines · Karsten Desler
Hi,
today I had a little more time to look at the code. A few lines down, there's another incarnation of the same bug.
Thanks, applied.
Signature · 1 line
/Martin
Quoted 10 lines · Karsten Desler
Hi,
And a couple more.
Attached are three patches.
iptables.patch - fixes for similar bugs in ip6tables,
iptables- and ip6tables-restore
extensions.patch - fixes for similar bugs in the extensions/
directory
libiptc.patch - simiar fix for libiptc
Applied slightly modified, you introduced some memory-corruption, arrays start at 0...
Thanks for all these fixes.
Signature · 1 line
/Martin