Article View: news.software.nntp
Article #19744Re: strlen of strncpy (1.6b2)
From: Francis C. Swasey
Date: Mon, 28 Jul 1997 00:00
Date: Mon, 28 Jul 1997 00:00
469 lines
18501 bytes
18501 bytes
Forrest is quite right. My patch is no better than the original 1.6b2
version, because I don't keep p pointing inside buff and there are
places where "*p" is blindly assigned a newline. Thus, here's a new
patch against the original files. The second patch following is if
you applied my first patch, to convert to the new patch.
Patch 1: Apply if you did not put on my first patch
------------------8<------------------8<-----------------8<-----------
--- innd/art.c.orig Wed Jul 23 13:09:28 1997
+++ innd/art.c Mon Jul 28 10:16:55 1997
@@ -2652,8 +2652,8 @@
ARTreject(buff, article);
return buff;
}
- p += strlen(strncpy(p, Data.Name, Files.Size - 1));
Files.Data[Files.Size - 1] = '\0';
+ p += strlen(strncpy(p, Data.Name, Files.Size - 1));
Data.NameLength = strlen(Data.Name);
}
else {
--- innd/cc.c.orig Wed Jul 23 13:09:28 1997
+++ innd/cc.c Mon Jul 28 10:19:31 1997
@@ -801,33 +801,33 @@
p += strlen(p);
break;
case OMrunning:
- p += strlen(strncpy(p, "running", sizeof(buff) - strlen(buff) - 1));
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, "running", sizeof(buff) - strlen(buff) - 1));
break;
case OMpaused:
+ buff[sizeof(buff) - 1] = '\0';
p += strlen(strncpy(p, "paused ", sizeof(buff) - strlen(buff) - 1));
buff[sizeof(buff) - 1] = '\0';
p += strlen(strncpy(p, ModeReason, sizeof(buff) - strlen(buff) - 1));
- buff[sizeof(buff) - 1] = '\0';
break;
case OMthrottled:
+ buff[sizeof(buff) - 1] = '\0';
p += strlen(strncpy(p, "throttled ", sizeof(buff) - strlen(buff) - 1));
buff[sizeof(buff) - 1] = '\0';
p += strlen(strncpy(p, ModeReason, sizeof(buff) - strlen(buff) - 1));
- buff[sizeof(buff) - 1] = '\0';
break;
}
*p++ = '\n';
if (RejectReason) {
+ buff[sizeof(buff) - 1] = '\0';
p += strlen(strncpy(p, "Rejecting ", sizeof(buff) - strlen(buff) - 1));
buff[sizeof(buff) - 1] = '\0';
p += strlen(strncpy(p, RejectReason, sizeof(buff) - strlen(buff) - 1));
- buff[sizeof(buff) - 1] = '\0';
}
else {
+ buff[sizeof(buff) - 1] = '\0';
p += strlen(strncpy(p, "Allowing remote connections",
sizeof(buff) - strlen(buff) - 1));
- buff[sizeof(buff) - 1] = '\0';
}
/* Server parameters. */
@@ -852,24 +852,24 @@
p += strlen(p);
}
else {
- p += strlen(strncpy(p, "Not reserved", sizeof(buff)-strlen(buff)-1));
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, "Not reserved", sizeof(buff)-strlen(buff)-1));
}
/* Newsreaders. */
*p++ = '\n';
- p += strlen(strncpy(p, "Readers ", sizeof(buff) - strlen(buff) - 1));
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, "Readers ", sizeof(buff) - strlen(buff) - 1));
if (NNRPFollows) {
- p += strlen(strncpy(p, "follow ", sizeof(buff) - strlen(buff) - 1));
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, "follow ", sizeof(buff) - strlen(buff) - 1));
} else {
- p += strlen(strncpy(p, "separate ", sizeof(buff) - strlen(buff) - 1));
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, "separate ", sizeof(buff) - strlen(buff) - 1));
}
if (NNRPReason == NULL) {
- p += strlen(strncpy(p, "enabled", sizeof(buff) - strlen(buff) - 1));
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, "enabled", sizeof(buff) - strlen(buff) - 1));
} else {
(void)snprintf(p, sizeof(buff) - strlen(buff),
"disabled %s", NNRPReason);
@@ -878,26 +878,26 @@
#if defined(DO_TCL)
*p++ = '\n';
- p += strlen(strncpy(p, "Tcl filtering ", sizeof(buff) - strlen(buff) - 1));
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, "Tcl filtering ", sizeof(buff) - strlen(buff) - 1));
if (TCLFilterActive) {
- p += strlen(strncpy(p, "enabled", sizeof(buff) - strlen(buff) - 1));
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, "enabled", sizeof(buff) - strlen(buff) - 1));
} else {
- p += strlen(strncpy(p, "disabled", sizeof(buff) - strlen(buff) - 1));
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, "disabled", sizeof(buff) - strlen(buff) - 1));
}
#endif /* defined(DO_TCL) */
#if defined(DO_PERL)
*p++ = '\n';
- p += strlen(strncpy(p, "Perl filtering ", sizeof(buff) - strlen(buff) - 1));
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, "Perl filtering ", sizeof(buff) - strlen(buff) - 1));
if (PerlFilterActive) {
- p += strlen(strncpy(p, "enabled", sizeof(buff) - strlen(buff) - 1));
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, "enabled", sizeof(buff) - strlen(buff) - 1));
} else {
- p += strlen(strncpy(p, "disabled", sizeof(buff) - strlen(buff) - 1));
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, "disabled", sizeof(buff) - strlen(buff) - 1));
}
#endif /* defined(DO_PERL) */
--- innd/site.c.orig Wed Jul 23 13:09:28 1997
+++ innd/site.c Mon Jul 28 10:20:42 1997
@@ -1173,17 +1173,17 @@
break;
case FTerror:
case FTfile:
- p += strlen(strncpy(p, "file", sizeof(buff) - strlen(buff) - 1));
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, "file", sizeof(buff) - strlen(buff) - 1));
if (sp->Buffered) {
(void)snprintf(p, sizeof(buff) - strlen(buff),
" buffered(%ld)", sp->Buffer.Left);
p += strlen(p);
}
else if ((cp = sp->Channel) == NULL) {
+ buff[sizeof(buff) - 1] = '\0';
p += strlen(strncpy(p, " no channel?",
sizeof(buff) - strlen(buff) - 1));
- buff[sizeof(buff) - 1] = '\0';
} else {
(void)snprintf(p, sizeof(buff) - strlen(buff),
" open fd=%d, in mem %ld", cp->fd, cp->Out.Left);
@@ -1191,12 +1191,12 @@
}
break;
case FTchannel:
- p += strlen(strncpy(p, "channel", sizeof(buff) - strlen(buff) - 1));
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, "channel", sizeof(buff) - strlen(buff) - 1));
goto Common;
case FTexploder:
- p += strlen(strncpy(p, "exploder", sizeof(buff) - strlen(buff) - 1));
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, "exploder", sizeof(buff) - strlen(buff) - 1));
Common:
if (sp->Process >= 0) {
(void)snprintf(p, sizeof(buff) - strlen(buff),
@@ -1204,13 +1204,13 @@
p += strlen(p);
}
if (sp->Spooling) {
- p += strlen(strncpy(p, " spooling", sizeof(buff)-strlen(buff)-1));
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, " spooling", sizeof(buff)-strlen(buff)-1));
}
if ((cp = sp->Channel) == NULL) {
+ buff[sizeof(buff) - 1] = '\0';
p += strlen(strncpy(p, " no channel?",
sizeof(buff) - strlen(buff) - 1));
- buff[sizeof(buff) - 1] = '\0';
} else {
(void)snprintf(p, sizeof(buff) - strlen(buff),
" fd=%d, in mem %ld", cp->fd, cp->Out.Left);
@@ -1218,20 +1218,20 @@
}
break;
case FTfunnel:
- p += strlen(strncpy(p,"recursive funnel",sizeof(buff)-strlen(buff)-1));
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p,"recursive funnel",sizeof(buff)-strlen(buff)-1));
break;
case FTlogonly:
- p += strlen(strncpy(p, "log only", sizeof(buff) - strlen(buff) - 1));
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, "log only", sizeof(buff) - strlen(buff) - 1));
break;
case FTprogram:
- p += strlen(strncpy(p, "program", sizeof(buff) - strlen(buff) - 1));
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, "program", sizeof(buff) - strlen(buff) - 1));
if (sp->FNLwantsnames) {
+ buff[sizeof(buff) - 1] = '\0';
p += strlen(strncpy(p, " with names",
sizeof(buff) - strlen(buff) - 1));
- buff[sizeof(buff) - 1] = '\0';
}
break;
}
--- lib/inndcomm.c.orig Wed Jul 23 13:09:28 1997
+++ lib/inndcomm.c Mon Jul 28 10:22:21 1997
@@ -234,8 +234,8 @@
for (p = buff + strlen(buff), i = 0; (q = argv[i]) != NULL; i++) {
*p++ = SC_SEP;
*p = '\0'; /* make sure buff is null-terminated so strlen below will work! */
- p += strlen(strncpy(p, q, bufsiz - strlen(buff) - 1 - HEADER_SIZE));
buff[bufsiz - 1 - HEADER_SIZE] = '\0';
+ p += strlen(strncpy(p, q, bufsiz - strlen(buff) - 1 - HEADER_SIZE));
}
/* Send message. */
------------------8<------------------8<-----------------8<-----------
Patch 2: Apply if you did put on my first patch from July 25th
------------------8<------------------8<-----------------8<-----------
--- innd/art.c.orig2 Fri Jul 25 18:28:44 1997
+++ innd/art.c Mon Jul 28 10:16:55 1997
@@ -2652,9 +2652,8 @@
ARTreject(buff, article);
return buff;
}
- (void)strncpy(p, Data.Name, Files.Size - 1);
- p += strlen(Data.Name);
Files.Data[Files.Size - 1] = '\0';
+ p += strlen(strncpy(p, Data.Name, Files.Size - 1));
Data.NameLength = strlen(Data.Name);
}
else {
--- innd/cc.c.orig2 Fri Jul 25 18:29:51 1997
+++ innd/cc.c Mon Jul 28 10:19:31 1997
@@ -801,41 +801,33 @@
p += strlen(p);
break;
case OMrunning:
- (void)strncpy(p, "running", sizeof(buff) - strlen(buff) - 1);
- p += strlen("running");
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, "running", sizeof(buff) - strlen(buff) - 1));
break;
case OMpaused:
- (void)strncpy(p, "paused ", sizeof(buff) - strlen(buff) - 1);
- p += strlen("paused ");
buff[sizeof(buff) - 1] = '\0';
- (void)strncpy(p, ModeReason, sizeof(buff) - strlen(buff) - 1);
- p += strlen(ModeReason);
+ p += strlen(strncpy(p, "paused ", sizeof(buff) - strlen(buff) - 1));
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, ModeReason, sizeof(buff) - strlen(buff) - 1));
break;
case OMthrottled:
- (void)strncpy(p, "throttled ", sizeof(buff) - strlen(buff) - 1);
- p += strlen("throttled ");
buff[sizeof(buff) - 1] = '\0';
- (void)strncpy(p, ModeReason, sizeof(buff) - strlen(buff) - 1);
- p += strlen(ModeReason);
+ p += strlen(strncpy(p, "throttled ", sizeof(buff) - strlen(buff) - 1));
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, ModeReason, sizeof(buff) - strlen(buff) - 1));
break;
}
*p++ = '\n';
if (RejectReason) {
- (void)strncpy(p, "Rejecting ", sizeof(buff) - strlen(buff) - 1);
- p += strlen("Rejecting ");
buff[sizeof(buff) - 1] = '\0';
- (void)strncpy(p, RejectReason, sizeof(buff) - strlen(buff) - 1);
- p += strlen(RejectReason);
+ p += strlen(strncpy(p, "Rejecting ", sizeof(buff) - strlen(buff) - 1));
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, RejectReason, sizeof(buff) - strlen(buff) - 1));
}
else {
- (void)strncpy(p, "Allowing remote connections",
- sizeof(buff) - strlen(buff) - 1);
- p += strlen("Allowing remote connections");
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, "Allowing remote connections",
+ sizeof(buff) - strlen(buff) - 1));
}
/* Server parameters. */
@@ -860,29 +852,24 @@
p += strlen(p);
}
else {
- (void)strncpy(p, "Not reserved", sizeof(buff)-strlen(buff)-1);
- p += strlen("Not reserved");
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, "Not reserved", sizeof(buff)-strlen(buff)-1));
}
/* Newsreaders. */
*p++ = '\n';
- (void)strncpy(p, "Readers ", sizeof(buff) - strlen(buff) - 1);
- p += strlen("Readers ");
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, "Readers ", sizeof(buff) - strlen(buff) - 1));
if (NNRPFollows) {
- (void)strncpy(p, "follow ", sizeof(buff) - strlen(buff) - 1);
- p += strlen("follow ");
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, "follow ", sizeof(buff) - strlen(buff) - 1));
} else {
- (void)strncpy(p, "separate ", sizeof(buff) - strlen(buff) - 1);
- p += strlen("separate ");
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, "separate ", sizeof(buff) - strlen(buff) - 1));
}
if (NNRPReason == NULL) {
- (void)strncpy(p, "enabled", sizeof(buff) - strlen(buff) - 1);
- p += strlen("enabled");
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, "enabled", sizeof(buff) - strlen(buff) - 1));
} else {
(void)snprintf(p, sizeof(buff) - strlen(buff),
"disabled %s", NNRPReason);
@@ -891,32 +878,26 @@
#if defined(DO_TCL)
*p++ = '\n';
- (void)strncpy(p, "Tcl filtering ", sizeof(buff) - strlen(buff) - 1);
- p += strlen("Tcl filtering ");
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, "Tcl filtering ", sizeof(buff) - strlen(buff) - 1));
if (TCLFilterActive) {
- (void)strncpy(p, "enabled", sizeof(buff) - strlen(buff) - 1);
- p += strlen("enabled");
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, "enabled", sizeof(buff) - strlen(buff) - 1));
} else {
- (void)strncpy(p, "disabled", sizeof(buff) - strlen(buff) - 1);
- p += strlen("disabled");
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, "disabled", sizeof(buff) - strlen(buff) - 1));
}
#endif /* defined(DO_TCL) */
#if defined(DO_PERL)
*p++ = '\n';
- (void)strncpy(p, "Perl filtering ", sizeof(buff) - strlen(buff) - 1);
- p += strlen("Perl filtering ");
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, "Perl filtering ", sizeof(buff) - strlen(buff) - 1));
if (PerlFilterActive) {
- (void)strncpy(p, "enabled", sizeof(buff) - strlen(buff) - 1);
- p += strlen("enabled");
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, "enabled", sizeof(buff) - strlen(buff) - 1));
} else {
- (void)strncpy(p, "disabled", sizeof(buff) - strlen(buff) - 1);
- p += strlen("disabled");
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, "disabled", sizeof(buff) - strlen(buff) - 1));
}
#endif /* defined(DO_PERL) */
--- innd/site.c.orig2 Fri Jul 25 18:24:55 1997
+++ innd/site.c Mon Jul 28 10:20:42 1997
@@ -1173,18 +1173,17 @@
break;
case FTerror:
case FTfile:
- (void)strncpy(p, "file", sizeof(buff) - strlen(buff) - 1);
- p += strlen("file");
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, "file", sizeof(buff) - strlen(buff) - 1));
if (sp->Buffered) {
(void)snprintf(p, sizeof(buff) - strlen(buff),
" buffered(%ld)", sp->Buffer.Left);
p += strlen(p);
}
else if ((cp = sp->Channel) == NULL) {
- (void)strncpy(p, " no channel?", sizeof(buff) - strlen(buff) - 1);
- p += strlen(" no channel?");
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, " no channel?",
+ sizeof(buff) - strlen(buff) - 1));
} else {
(void)snprintf(p, sizeof(buff) - strlen(buff),
" open fd=%d, in mem %ld", cp->fd, cp->Out.Left);
@@ -1192,14 +1191,12 @@
}
break;
case FTchannel:
- (void)strncpy(p, "channel", sizeof(buff) - strlen(buff) - 1);
- p += strlen("channel");
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, "channel", sizeof(buff) - strlen(buff) - 1));
goto Common;
case FTexploder:
- (void)strncpy(p, "exploder", sizeof(buff) - strlen(buff) - 1);
- p += strlen("exploder");
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, "exploder", sizeof(buff) - strlen(buff) - 1));
Common:
if (sp->Process >= 0) {
(void)snprintf(p, sizeof(buff) - strlen(buff),
@@ -1207,14 +1204,13 @@
p += strlen(p);
}
if (sp->Spooling) {
- (void)strncpy(p, " spooling", sizeof(buff)-strlen(buff)-1);
- p += strlen(" spooling");
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, " spooling", sizeof(buff)-strlen(buff)-1));
}
if ((cp = sp->Channel) == NULL) {
- (void)strncpy(p, " no channel?", sizeof(buff) - strlen(buff) - 1);
- p += strlen(" no channel?");
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, " no channel?",
+ sizeof(buff) - strlen(buff) - 1));
} else {
(void)snprintf(p, sizeof(buff) - strlen(buff),
" fd=%d, in mem %ld", cp->fd, cp->Out.Left);
@@ -1222,23 +1218,20 @@
}
break;
case FTfunnel:
- (void)strncpy(p,"recursive funnel",sizeof(buff)-strlen(buff)-1);
- p += strlen("recursive funnel");
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p,"recursive funnel",sizeof(buff)-strlen(buff)-1));
break;
case FTlogonly:
- (void)strncpy(p, "log only", sizeof(buff) - strlen(buff) - 1);
- p += strlen("log only");
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, "log only", sizeof(buff) - strlen(buff) - 1));
break;
case FTprogram:
- (void)strncpy(p, "program", sizeof(buff) - strlen(buff) - 1);
- p += strlen("program");
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, "program", sizeof(buff) - strlen(buff) - 1));
if (sp->FNLwantsnames) {
- (void)strncpy(p, " with names", sizeof(buff) - strlen(buff) - 1);
- p += strlen(" with names");
buff[sizeof(buff) - 1] = '\0';
+ p += strlen(strncpy(p, " with names",
+ sizeof(buff) - strlen(buff) - 1));
}
break;
}
--- lib/inndcomm.c.orig2 Fri Jul 25 18:25:23 1997
+++ lib/inndcomm.c Mon Jul 28 10:22:21 1997
@@ -234,9 +234,8 @@
for (p = buff + strlen(buff), i = 0; (q = argv[i]) != NULL; i++) {
*p++ = SC_SEP;
*p = '\0'; /* make sure buff is null-terminated so strlen below will work! */
- (void)strncpy(p, q, bufsiz - strlen(buff) - 1 - HEADER_SIZE);
- p += strlen(q);
buff[bufsiz - 1 - HEADER_SIZE] = '\0';
+ p += strlen(strncpy(p, q, bufsiz - strlen(buff) - 1 - HEADER_SIZE));
}
/* Send message. */
------------------8<------------------8<-----------------8<-----------
Frank
--
e-mail: fswasey@btv.ibm.com ,,,
Tel: 802-769-4011 (tie: 446), Fax: 802-769-4253 (tie: 446) (o o)
Speaking *from* but not *for* IBM -oOOO--(_)--OOOo-
Technical Details
Message-ID:
<5ric8c$r0m@fangorn.btv.ibm.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-mailReferences:
<5rba4b$6e2@fangorn.btv.ibm.com> <5rhtgj$rch$1@news1.epix.net>Show Full Headers
Complete Article Headers
Message-ID: <5ric8c$r0m@fangorn.btv.ibm.com> Subject: Re: strlen of strncpy (1.6b2) Date: Mon, 28 Jul 1997 00:00:00 +0000 From: fswasey@fangorn.btv.ibm.com (Francis C. Swasey) References: <5rba4b$6e2@fangorn.btv.ibm.com> <5rhtgj$rch$1@news1.epix.net> 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: 259810001 Organization: International Business Machines Reply-To: fswasey@btv.ibm.com Newsgroups: news.software.nntp