All of lore.kernel.org
 help / color / mirror / Atom feed
* Buffer of by one in iptables.c in iptables v1.2.7a
@ 2003-02-21 14:24 Arvanitis Kostas
  2003-02-23 11:41 ` Patrick Schaaf
  0 siblings, 1 reply; 2+ messages in thread
From: Arvanitis Kostas @ 2003-02-21 14:24 UTC (permalink / raw)
  To: netfilter-devel; +Cc: arvanit

The line in find_target() that reads:

char path[sizeof(IPT_LIB_DIR) + sizeof("/libipt_.so") + strlen(name)]

is used as the target buffer for a sprintf() statement. However sprintf will 
also append a '\0' after the string, so the corrected line should be:

char path[sizeof(IPT_LIB_DIR) + sizeof("/libipt_.so") + strlen(name)+1]

This does not seem to affect the program, since path[] is allocated on the 
stack and there is nothing following it. However, for the shake of 
completeness, I think it should be corrected.

PS: Keep up the good work.
PS2: Is there a thought for iptables to take src/dst addresses as ranges in 
the form of ip_low - ip_high? (so as to be more compatible with the NAT-MIB)
-- 
A: No. See http://www.netmeister.org/news/learn2quote.html
Q: Should I include quotations after my reply ?

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Buffer of by one in iptables.c in iptables v1.2.7a
  2003-02-21 14:24 Buffer of by one in iptables.c in iptables v1.2.7a Arvanitis Kostas
@ 2003-02-23 11:41 ` Patrick Schaaf
  0 siblings, 0 replies; 2+ messages in thread
From: Patrick Schaaf @ 2003-02-23 11:41 UTC (permalink / raw)
  To: Arvanitis Kostas; +Cc: netfilter-devel

On Fri, Feb 21, 2003 at 04:24:05PM +0200, Arvanitis Kostas wrote:
> The line in find_target() that reads:
> 
> char path[sizeof(IPT_LIB_DIR) + sizeof("/libipt_.so") + strlen(name)]
> 
> is used as the target buffer for a sprintf() statement.

That is probably correct, although a bit subtle.

You did not show the format string used later, and I'm too lazy do
dig for the source, but I guess it will be something like

	sprintf(path, IPT_LIB_DIR "/libipt_%s.so", name);

Right?

Now, count the characters again, with an eye not on the path[sizeof]
stuff, but on the actual format string. Note how the value of 'name'
will be embedded in the formatted string: it does not need a '\0' in
that representation.

Also note that the two sizeofs each contribute one '\0' (their args
being constant C strings), but only one of them is needed for
sprintf() to properly terminate the result. So, if I don't
miscount, there's even one surplus byte in path[].

This should fix that:

	char path[sizeof(IPT_LIB_DIR "/libipt_.so") + strlen(name)]

best regards
  Patrick

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-02-23 11:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-02-21 14:24 Buffer of by one in iptables.c in iptables v1.2.7a Arvanitis Kostas
2003-02-23 11:41 ` Patrick Schaaf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.