Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/mail Defensively rewrite a string moving loop.
details: https://anonhg.NetBSD.org/src/rev/4a8768a6cbc7
branches: trunk
changeset: 554645:4a8768a6cbc7
user: ross <ross%NetBSD.org@localhost>
date: Fri Oct 31 01:25:54 2003 +0000
description:
Defensively rewrite a string moving loop.
Constify.
Check for an allocation error.
diffstat:
usr.bin/mail/cmd3.c | 13 +++++++++----
usr.bin/mail/extern.h | 10 +++++-----
usr.bin/mail/fio.c | 6 +++---
usr.bin/mail/support.c | 8 ++++----
usr.bin/mail/vars.c | 6 ++++--
5 files changed, 25 insertions(+), 18 deletions(-)
diffs (170 lines):
diff -r da6fc93eb74a -r 4a8768a6cbc7 usr.bin/mail/cmd3.c
--- a/usr.bin/mail/cmd3.c Fri Oct 31 01:12:06 2003 +0000
+++ b/usr.bin/mail/cmd3.c Fri Oct 31 01:25:54 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cmd3.c,v 1.22 2003/10/29 05:11:26 ross Exp $ */
+/* $NetBSD: cmd3.c,v 1.23 2003/10/31 01:25:54 ross Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)cmd3.c 8.2 (Berkeley) 4/20/95";
#else
-__RCSID("$NetBSD: cmd3.c,v 1.22 2003/10/29 05:11:26 ross Exp $");
+__RCSID("$NetBSD: cmd3.c,v 1.23 2003/10/31 01:25:54 ross Exp $");
#endif
#endif /* not lint */
@@ -363,6 +363,7 @@
char *cp, *cp2;
char varbuf[BUFSIZ], **ap, **p;
int errs, h, s;
+ size_t l;
if (*arglist == NULL) {
for (h = 0, s = 1; h < HSHSIZE; h++)
@@ -383,8 +384,12 @@
cp = *ap;
cp2 = varbuf;
while (*cp != '=' && *cp != '\0')
- *cp2++ = *cp++;
- *cp2 = '\0';
+ ++cp;
+ l = cp - *ap;
+ if (l >= sizeof varbuf)
+ l = sizeof varbuf - 1;
+ strncpy(cp2, *ap, l);
+ ap[0][l] = '\0';
if (*cp == '\0')
cp = "";
else
diff -r da6fc93eb74a -r 4a8768a6cbc7 usr.bin/mail/extern.h
--- a/usr.bin/mail/extern.h Fri Oct 31 01:12:06 2003 +0000
+++ b/usr.bin/mail/extern.h Fri Oct 31 01:25:54 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: extern.h,v 1.18 2003/08/07 11:14:37 agc Exp $ */
+/* $NetBSD: extern.h,v 1.19 2003/10/31 01:25:54 ross Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -29,7 +29,7 @@
* SUCH DAMAGE.
*
* @(#)extern.h 8.2 (Berkeley) 4/20/95
- * $NetBSD: extern.h,v 1.18 2003/08/07 11:14:37 agc Exp $
+ * $NetBSD: extern.h,v 1.19 2003/10/31 01:25:54 ross Exp $
*/
struct name;
@@ -56,9 +56,9 @@
char *getdeadletter(void);
const char *getname(int);
struct message;
-char *hfield(char [], struct message *);
+char *hfield(const char [], const struct message *);
FILE *infix(struct header *, FILE *);
-char *ishfield(char [], char[], char *);
+char *ishfield(const char [], char[], const char *);
char *name1(struct message *, int);
char *nameof(struct message *, int);
char *nextword(char *, char *);
@@ -67,7 +67,7 @@
FILE *run_editor(FILE *, off_t, int, int);
char *salloc(int);
char *savestr(const char *);
-FILE *setinput(struct message *);
+FILE *setinput(const struct message *);
char *skin(char *);
char *skip_comment(char *);
char *snarf(char [], int *);
diff -r da6fc93eb74a -r 4a8768a6cbc7 usr.bin/mail/fio.c
--- a/usr.bin/mail/fio.c Fri Oct 31 01:12:06 2003 +0000
+++ b/usr.bin/mail/fio.c Fri Oct 31 01:25:54 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fio.c,v 1.22 2003/08/07 11:14:37 agc Exp $ */
+/* $NetBSD: fio.c,v 1.23 2003/10/31 01:25:54 ross Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)fio.c 8.2 (Berkeley) 4/20/95";
#else
-__RCSID("$NetBSD: fio.c,v 1.22 2003/08/07 11:14:37 agc Exp $");
+__RCSID("$NetBSD: fio.c,v 1.23 2003/10/31 01:25:54 ross Exp $");
#endif
#endif /* not lint */
@@ -218,7 +218,7 @@
* passed message pointer.
*/
FILE *
-setinput(struct message *mp)
+setinput(const struct message *mp)
{
fflush(otf);
diff -r da6fc93eb74a -r 4a8768a6cbc7 usr.bin/mail/support.c
--- a/usr.bin/mail/support.c Fri Oct 31 01:12:06 2003 +0000
+++ b/usr.bin/mail/support.c Fri Oct 31 01:25:54 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: support.c,v 1.10 2003/08/07 11:14:42 agc Exp $ */
+/* $NetBSD: support.c,v 1.11 2003/10/31 01:25:54 ross Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)aux.c 8.1 (Berkeley) 6/6/93";
#else
-__RCSID("$NetBSD: support.c,v 1.10 2003/08/07 11:14:42 agc Exp $");
+__RCSID("$NetBSD: support.c,v 1.11 2003/10/31 01:25:54 ross Exp $");
#endif
#endif /* not lint */
@@ -128,7 +128,7 @@
* pointer (or NULL if the desired header field is not available).
*/
char *
-hfield(char field[], struct message *mp)
+hfield(const char field[], const struct message *mp)
{
FILE *ibuf;
char linebuf[LINESIZE];
@@ -212,7 +212,7 @@
*/
char*
-ishfield(char linebuf[], char *colon, char field[])
+ishfield(const char linebuf[], char *colon, const char field[])
{
char *cp = colon;
diff -r da6fc93eb74a -r 4a8768a6cbc7 usr.bin/mail/vars.c
--- a/usr.bin/mail/vars.c Fri Oct 31 01:12:06 2003 +0000
+++ b/usr.bin/mail/vars.c Fri Oct 31 01:25:54 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vars.c,v 1.11 2003/08/07 11:14:42 agc Exp $ */
+/* $NetBSD: vars.c,v 1.12 2003/10/31 01:25:54 ross Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)vars.c 8.1 (Berkeley) 6/6/93";
#else
-__RCSID("$NetBSD: vars.c,v 1.11 2003/08/07 11:14:42 agc Exp $");
+__RCSID("$NetBSD: vars.c,v 1.12 2003/10/31 01:25:54 ross Exp $");
#endif
#endif /* not lint */
@@ -60,6 +60,8 @@
vp = lookup(name);
if (vp == NULL) {
vp = (struct var *) calloc(1, sizeof *vp);
+ if (vp == NULL)
+ errx(1, "Out of memory");
vp->v_name = vcopy(name);
vp->v_link = variables[h];
variables[h] = vp;
Home |
Main Index |
Thread Index |
Old Index