Date: Sun, 28 Jan 2001 04:10:03 -0800 (PST) From: "Klaus A. Brunner" <k.brunner@acm.org> To: freebsd-bugs@FreeBSD.org Subject: Re: bin/24683: obscure natd(8) error message Message-ID: <200101281210.f0SCA3x92300@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/24683; it has been noted by GNATS. From: "Klaus A. Brunner" <k.brunner@acm.org> To: freebsd-gnats-submit@FreeBSD.org, klaus@winf.htu.tuwien.ac.at Cc: Subject: Re: bin/24683: obscure natd(8) error message Date: Sun, 28 Jan 2001 13:01:48 +0100 This is a multi-part message in MIME format. --------------C13813343533D3E74851CCCD Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Here's a slightly extended patch which also substitutes snprintf() for sprintf(). --------------C13813343533D3E74851CCCD Content-Type: text/plain; charset=us-ascii; name="natd.newpatch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="natd.newpatch" Index: natd/natd.c =================================================================== RCS file: /home/ncvs/src/sbin/natd/natd.c,v retrieving revision 1.25.2.3 diff -u -r1.25.2.3 natd.c --- natd/natd.c 2000/07/11 20:00:57 1.25.2.3 +++ natd/natd.c 2001/01/28 11:57:13 @@ -586,7 +586,7 @@ static void FlushPacketBuffer (int fd) { int wrote; - char msgBuf[80]; + char msgBuf[160]; /* * Put packet back for processing. */ @@ -616,10 +616,12 @@ } else { - sprintf (msgBuf, "failed to write packet back"); + snprintf (msgBuf, sizeof(msgBuf), + "failed to write packet back (%s)", + FormatPacket((struct ip*)packetBuf); Warn (msgBuf); } - } + } packetSock = -1; } @@ -680,7 +682,8 @@ switch (ip->ip_p) { case IPPROTO_TCP: tcphdr = (struct tcphdr*) ((char*) ip + (ip->ip_hl << 2)); - sprintf (buf, "[TCP] %s:%d -> %s:%d", + snprintf (buf, sizeof(buf), + "[TCP] %s:%d -> %s:%d", src, ntohs (tcphdr->th_sport), dst, @@ -689,7 +692,8 @@ case IPPROTO_UDP: udphdr = (struct udphdr*) ((char*) ip + (ip->ip_hl << 2)); - sprintf (buf, "[UDP] %s:%d -> %s:%d", + snprintf (buf, sizeof(buf), + "[UDP] %s:%d -> %s:%d", src, ntohs (udphdr->uh_sport), dst, @@ -698,7 +702,8 @@ case IPPROTO_ICMP: icmphdr = (struct icmp*) ((char*) ip + (ip->ip_hl << 2)); - sprintf (buf, "[ICMP] %s -> %s %u(%u)", + snprintf (buf, sizeof(buf), + "[ICMP] %s -> %s %u(%u)", src, dst, icmphdr->icmp_type, @@ -706,7 +711,8 @@ break; default: - sprintf (buf, "[%d] %s -> %s ", ip->ip_p, src, dst); + snprintf (buf, sizeof(buf), "[%d] %s -> %s ", + ip->ip_p, src, dst); break; } --------------C13813343533D3E74851CCCD-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200101281210.f0SCA3x92300>