🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #19644

Re: ANNOUNCE: INN 1.5.1 buffer overflow patch

#19644
From: Miquel van Smoorenburg
Date: Fri, 25 Jul 1997 00:00
34 lines
1826 bytes
In article <33D7E146.95CD5BC@spinne.com>,
Jeff Garzik  <jeff.garzik@spinne.com> wrote:
>(cc'd to author)
>
>Read your manpage....  strncpy will never insert a terminating null past
>the size arg.  Doing so would defeat the purpose of strncpy().  Doing a 
>
>	buff[sizeof(buff) - 1] = '\0';
>
>after EACH and EVERY strncpy() is quite necessary.

You're right. My manual page says:

       In the case where the length of src is less than  that  of
       n, the remainder of dest will be padded with nulls.

Ofcourse, strlen(src) >= n is just the case we want to prevent.

I've fixed my patch to use

#define STRCPY(dst, src) \
	(dst[sizeof(dst) - 1] = 0, strncpy(dst, src, sizeof(dst) - 1))

The first part sets the last byte to \0, the strncpy copies one byte less
then the dst length so the last \0 does not get overwritten.

Mike.
-- 
| Miquel van Smoorenburg |  "I need more space" "Well, why not move to Texas" |
| miquels@cistron.nl     |  "No, on my account, stupid." "Stupid? Uh-oh.."    |
|     PGP fingerprint: FE 66 52 4F CD 59 A5 36  7F 39 8B 20 F1 D6 74 02       |

Technical Details
Message-ID: <5r9m1a$6oe$1@holodeck.cistron.nl>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail
References: <5r81l9$27j$1@holodeck.cistron.nl> <5r8944$7d3$1@news1.epix.net> <5r8a6h$30f$1@holodeck.cistron.nl> <33D7E146.95CD5BC@spinne.com>

Show Full Headers
Complete Article Headers
Message-ID: <5r9m1a$6oe$1@holodeck.cistron.nl>
Subject: Re: ANNOUNCE: INN 1.5.1 buffer overflow patch
Date: Fri, 25 Jul 1997 00:00:00 +0000
From: miquels@cistron.nl (Miquel van Smoorenburg)
References: <5r81l9$27j$1@holodeck.cistron.nl> <5r8944$7d3$1@news1.epix.net> <5r8a6h$30f$1@holodeck.cistron.nl> <33D7E146.95CD5BC@spinne.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail
X-Deja-AN: 258688638
Organization: Cistron Internet Services B.V.
X-Server-Date: 25 Jul 1997 07:53:09 GMT
Newsgroups: news.software.nntp