Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/msgs - Use strlcpy(), snprintf().
details: https://anonhg.NetBSD.org/src/rev/20e4e047be0c
branches: trunk
changeset: 494447:20e4e047be0c
user: ad <ad%NetBSD.org@localhost>
date: Thu Jul 06 14:21:47 2000 +0000
description:
- Use strlcpy(), snprintf().
- Use MAXPATHLEN.
- printf fmt string without %s, from OpenBSD.
diffstat:
usr.bin/msgs/msgs.c | 34 ++++++++++++++++++----------------
1 files changed, 18 insertions(+), 16 deletions(-)
diffs (127 lines):
diff -r c77ea7b3609d -r 20e4e047be0c usr.bin/msgs/msgs.c
--- a/usr.bin/msgs/msgs.c Thu Jul 06 14:13:05 2000 +0000
+++ b/usr.bin/msgs/msgs.c Thu Jul 06 14:21:47 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: msgs.c,v 1.15 1999/06/13 19:38:05 kleink Exp $ */
+/* $NetBSD: msgs.c,v 1.16 2000/07/06 14:21:47 ad Exp $ */
/*-
* Copyright (c) 1980, 1993
@@ -43,7 +43,7 @@
#if 0
static char sccsid[] = "@(#)msgs.c 8.2 (Berkeley) 4/28/95";
#else
-__RCSID("$NetBSD: msgs.c,v 1.15 1999/06/13 19:38:05 kleink Exp $");
+__RCSID("$NetBSD: msgs.c,v 1.16 2000/07/06 14:21:47 ad Exp $");
#endif
#endif /* not lint */
@@ -115,8 +115,8 @@
FILE *newmsg;
char *sep = "-";
char inbuf[BUFSIZ];
-char fname[128];
-char cmdbuf[128];
+char fname[MAXPATHLEN];
+char cmdbuf[MAXPATHLEN + 16];
char subj[128];
char from[128];
char date[128];
@@ -254,7 +254,7 @@
/*
* determine current message bounds
*/
- sprintf(fname, "%s/%s", _PATH_MSGS, BOUNDS);
+ snprintf(fname, sizeof (fname), "%s/%s", _PATH_MSGS, BOUNDS);
bounds = fopen(fname, "r");
if (bounds != NULL) {
@@ -295,7 +295,8 @@
#endif
if (clean)
- sprintf(inbuf, "%s/%s", _PATH_MSGS, cp);
+ snprintf(inbuf, sizeof (inbuf), "%s/%s",
+ _PATH_MSGS, cp);
while (isdigit((unsigned char)*cp))
i = i * 10 + *cp++ - '0';
@@ -351,7 +352,7 @@
}
nextmsg = lastmsg + 1;
- sprintf(fname, "%s/%d", _PATH_MSGS, nextmsg);
+ snprintf(fname, sizeof (fname), "%s/%d", _PATH_MSGS, nextmsg);
newmsg = fopen(fname, "w");
if (newmsg == NULL) {
perror(fname);
@@ -412,7 +413,7 @@
totty = (isatty(fileno(stdout)) != 0);
use_pager = use_pager && totty;
- sprintf(fname, "%s/%s", getenv("HOME"), MSGSRC);
+ snprintf(fname, sizeof (fname), "%s/%s", getenv("HOME"), MSGSRC);
msgsrc = fopen(fname, "r");
if (msgsrc) {
newrc = NO;
@@ -478,7 +479,7 @@
*/
for (msg = firstmsg; msg <= lastmsg; msg++) {
- sprintf(fname, "%s/%d", _PATH_MSGS, msg);
+ snprintf(fname, sizeof (fname), "%s/%d", _PATH_MSGS, msg);
newmsg = fopen(fname, "r");
if (newmsg == NULL)
continue;
@@ -636,9 +637,10 @@
signal(SIGQUIT, SIG_IGN);
if ((env_pager = getenv("PAGER")) == NULL ||
env_pager[0] == '\0') {
- sprintf(cmdbuf, _PATH_PAGER, Lpp);
+ snprintf(cmdbuf, sizeof(cmdbuf), "%s -z%d",
+ _PATH_PAGER, Lpp);
} else {
- strcpy(cmdbuf, env_pager);
+ strlcpy(cmdbuf, env_pager, sizeof (cmdbuf));
}
outf = popen(cmdbuf, "w");
if (!outf)
@@ -733,7 +735,7 @@
{
int i;
sscanf(buf, "%d", &i);
- sprintf(buf, "Goto %d", i);
+ snprintf(buf, sizeof (buf), "Goto %d", i);
return(--i);
}
@@ -765,7 +767,7 @@
cmsg = atoi(&inbuf[1]);
else
cmsg = msg;
- sprintf(fname, "%s/%d", _PATH_MSGS, cmsg);
+ snprintf(fname, sizeof (fname), "%s/%d", _PATH_MSGS, cmsg);
oldpos = ftell(newmsg);
@@ -785,17 +787,17 @@
fname[n] = '\0';
}
else
- strcpy(fname, "Messages");
+ strlcpy(fname, "Messages", sizeof(fname));
}
else {
int fd;
- strcpy(fname, _PATH_TMP);
+ strlcpy(fname, _PATH_TMP, sizeof(fname));
fd = mkstemp(fname);
if (fd == -1)
err(1, "mkstemp failed");
close(fd);
- sprintf(cmdbuf, _PATH_MAIL, fname);
+ snprintf(cmdbuf, sizeof (cmdbuf), _PATH_MAIL, fname);
mailing = YES;
}
cpto = fopen(fname, "a");
Home |
Main Index |
Thread Index |
Old Index