Article View: news.software.nntp
Article #19655INN 1.5.1: Strcpy() considered harmful?
From: Yar Tikhiy
Date: Fri, 25 Jul 1997 00:00
Date: Fri, 25 Jul 1997 00:00
171 lines
5964 bytes
5964 bytes
Hello everybody,
The following text is just my humble opinion and I'd appreciate
any corrections, comments and criticisms.
As I've got sick of my uncertainty about the security holes
I greped INN 1.5.1 sources for "strcpy" and "sprintf.*%s"
(as I do not remember INN sources by heart yet) and then RTFS.
Let strcpy() or sprintf() be considered harmful if and only if
it gets _unpredictable_ (unrestricted by other code, in another
words) data supplied by a user. I've managed to find such harmful
calls only in nnrpd/post.c (innlib seems not to have suspicious calls
at all and innd has a protection against artifically oversized strings
by means of MaxLength() call). The calls fall into 2 groups:
a) Calls of "sprintf(Error,...)" group. They are not
actually harmful in spite of the above definition :) as "Error" is
a static variable and nnrpd bails out very soon after the variable
is set, so it's quite hard to make an exploit of its overflow.
However, I'd feel myself more comfortably if the overflows did not
take place at all, so the harmful calls are in lines 217, 241, 604,
620 and 627 of nnrpd/post.c. Other sprintf(Error,...) calls does not
seem harmful as theis arguments' maximum size can be predicted and
will not exceed SMBUF.
b) strcpy() calls. There is a really nasty one noticed by
everybody (line 801):
strcpy(frombuf, HDR(_from));
and another (line 911) that looks nasty, but IMHO is actually
unexploitable:
(void)strcpy(idbuff, HDR(_messageid));
as the strcpy() take place only if the post was successful, and
innd has it's own Message-ID check that restricts its length to
DBZMAXKEY bytes (255). As the 'idbuff' is SMBUF bytes long (256
by default), either article's Message-ID will fit into 'idbuff'
or the article will be rejected by innd. However, the piece of
nnrpd is harmful by the definition :)
So, that's the patch.
*** post.c.orig Tue Dec 17 17:40:40 1996
--- post.c Fri Jul 25 21:27:27 1997
***************
*** 214,220 ****
/* SUPPRESS 530 *//* Empty body for statement */
;
else {
! (void)sprintf(Error, "\"%s\" is not a valid control message",
ctrl);
return Error;
}
--- 214,220 ----
/* SUPPRESS 530 *//* Empty body for statement */
;
else {
! (void)snprintf(Error, sizeof(Error), "\"%s\" is not a valid control message",
ctrl);
return Error;
}
***************
*** 238,244 ****
do {
for (dp = BadDistribs; *dp; dp++)
if (wildmat(p, *dp)) {
! (void)sprintf(Error, "Illegal distribution \"%s\"", p);
return Error;
}
} while ((p = strtok((char *)NULL, SEPS)) != NULL);
--- 238,244 ----
do {
for (dp = BadDistribs; *dp; dp++)
if (wildmat(p, *dp)) {
! (void)snprintf(Error, sizeof(Error), "Illegal distribution \"%s\"", p);
return Error;
}
} while ((p = strtok((char *)NULL, SEPS)) != NULL);
***************
*** 601,607 ****
break;
case NF_FLAG_IGNORE:
case NF_FLAG_NOLOCAL:
! (void)sprintf(Error, "Postings to \"%s\" are not allowed here.",
gp->Name);
break;
case NF_FLAG_EXCLUDED:
--- 601,607 ----
break;
case NF_FLAG_IGNORE:
case NF_FLAG_NOLOCAL:
! (void)snprintf(Error, sizeof(Error), "Postings to \"%s\" are not allowed here.",
gp->Name);
break;
case NF_FLAG_EXCLUDED:
***************
*** 617,630 ****
grplist[0] = p;
grplist[1] = NULL;
if (!PERMmatch(PERMdefault, PERMlist, grplist)) {
! sprintf(Error,"%s: %s\r\n", NNTP_NOSUCHGROUP,p);
}
}
} while ((p = strtok((char *)NULL, NGSEPS)) != NULL);
DISPOSE(groups);
if (!FoundOne && !IsNewgroup)
! (void)sprintf(Error, "No valid newsgroups in \"%s\"", hdr);
if (Error[0]) {
DISPOSE(DDend(h));
return Error;
--- 617,630 ----
grplist[0] = p;
grplist[1] = NULL;
if (!PERMmatch(PERMdefault, PERMlist, grplist)) {
! snprintf(Error,sizeof(Error),"%s: %s\r\n", NNTP_NOSUCHGROUP,p);
}
}
} while ((p = strtok((char *)NULL, NGSEPS)) != NULL);
DISPOSE(groups);
if (!FoundOne && !IsNewgroup)
! (void)snprintf(Error, sizeof(Error), "No valid newsgroups in \"%s\"", hdr);
if (Error[0]) {
DISPOSE(DDend(h));
return Error;
***************
*** 798,804 ****
if (idbuff != NULL)
idbuff [0] = '\0' ;
! strcpy(frombuf, HDR(_from));
HeaderCleanFrom(frombuf);
p = strchr(frombuf, '@');
if (p) {
--- 798,805 ----
if (idbuff != NULL)
idbuff [0] = '\0' ;
! strncpy(frombuf, HDR(_from), sizeof(frombuf)-1);
! frombuf[sizeof(frombuf)-1]='\0';
HeaderCleanFrom(frombuf);
p = strchr(frombuf, '@');
if (p) {
***************
*** 908,913 ****
/* Send a quit and close down */
SendQuit(FromServer, ToServer);
if (idbuff)
! (void)strcpy(idbuff, HDR(_messageid));
return NULL;
}
--- 909,922 ----
/* Send a quit and close down */
SendQuit(FromServer, ToServer);
if (idbuff)
! {
! /*
! * XXX A lame hack:
! * the knowledge about idbuff size is external to the current
! * function. However, the function is called only once.
! */
! (void)strncpy(idbuff, HDR(_messageid), SMBUF-1);
! idbuff[SMBUF-1]='\0';
! }
return NULL;
}
SY, Yar
Technical Details
Message-ID:
<5rap3k$6ac$1@comp.chem.msu.su>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-mailShow Full Headers
Complete Article Headers
Message-ID: <5rap3k$6ac$1@comp.chem.msu.su> Subject: INN 1.5.1: Strcpy() considered harmful? Date: Fri, 25 Jul 1997 00:00:00 +0000 From: Yar Tikhiy <yar@comp.chem.msu.su> 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: 258892825 Organization: Chemistry Department, MSU Newsgroups: news.software.nntp