diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2001-11-21 20:41:57 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2001-11-21 20:41:57 +0000 |
commit | c24e90e0637476fbd9d6983cfb62b935af4c7d97 (patch) | |
tree | 6aa744dff04bf458c68ddd45a9ef889f3086688e | |
parent | 9e53048fff7853801448fee927bc5bae4c8b4a91 (diff) |
o kill strcpy()
o check return values of malloc and friends
o use strdup() when sensible
-rw-r--r-- | usr.bin/mail/cmd1.c | 9 | ||||
-rw-r--r-- | usr.bin/mail/cmd2.c | 11 | ||||
-rw-r--r-- | usr.bin/mail/cmd3.c | 28 | ||||
-rw-r--r-- | usr.bin/mail/lex.c | 16 | ||||
-rw-r--r-- | usr.bin/mail/list.c | 6 | ||||
-rw-r--r-- | usr.bin/mail/names.c | 7 | ||||
-rw-r--r-- | usr.bin/mail/popen.c | 9 | ||||
-rw-r--r-- | usr.bin/mail/tty.c | 6 | ||||
-rw-r--r-- | usr.bin/mail/vars.c | 7 |
9 files changed, 55 insertions, 44 deletions
diff --git a/usr.bin/mail/cmd1.c b/usr.bin/mail/cmd1.c index e69b57a9b6d..eb7e5daa751 100644 --- a/usr.bin/mail/cmd1.c +++ b/usr.bin/mail/cmd1.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd1.c,v 1.21 2001/11/21 15:26:39 millert Exp $ */ +/* $OpenBSD: cmd1.c,v 1.22 2001/11/21 20:41:55 millert Exp $ */ /* $NetBSD: cmd1.c,v 1.9 1997/07/09 05:29:48 mikel Exp $ */ /*- @@ -38,7 +38,7 @@ #if 0 static const char sccsid[] = "@(#)cmd1.c 8.2 (Berkeley) 4/20/95"; #else -static const char rcsid[] = "$OpenBSD: cmd1.c,v 1.21 2001/11/21 15:26:39 millert Exp $"; +static const char rcsid[] = "$OpenBSD: cmd1.c,v 1.22 2001/11/21 20:41:55 millert Exp $"; #endif #endif /* not lint */ @@ -491,9 +491,8 @@ folders(void *v) char dirname[PATHSIZE]; char cmd[BUFSIZ]; - if (getfold(dirname, sizeof(dirname)) < 0) { - strcpy(dirname, "$HOME"); - } + if (getfold(dirname, sizeof(dirname)) < 0) + strlcpy(dirname, "$HOME", sizeof(dirname)); snprintf(cmd, sizeof(cmd), "cd %s; %s %s", dirname, value("LISTER"), files && *files ? files : ""); diff --git a/usr.bin/mail/cmd2.c b/usr.bin/mail/cmd2.c index 2d3d3c595bf..e8621d264e7 100644 --- a/usr.bin/mail/cmd2.c +++ b/usr.bin/mail/cmd2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd2.c,v 1.10 2001/11/21 15:26:39 millert Exp $ */ +/* $OpenBSD: cmd2.c,v 1.11 2001/11/21 20:41:55 millert Exp $ */ /* $NetBSD: cmd2.c,v 1.7 1997/05/17 19:55:10 pk Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static const char sccsid[] = "@(#)cmd2.c 8.1 (Berkeley) 6/6/93"; #else -static const char rcsid[] = "$OpenBSD: cmd2.c,v 1.10 2001/11/21 15:26:39 millert Exp $"; +static const char rcsid[] = "$OpenBSD: cmd2.c,v 1.11 2001/11/21 20:41:55 millert Exp $"; #endif #endif /* not lint */ @@ -466,8 +466,11 @@ ignore1(char **list, struct ignoretab *tab, char *which) continue; h = hash(field); igp = (struct ignore *)calloc(1, sizeof(struct ignore)); - igp->i_field = (char *)calloc(strlen(field) + 1, sizeof(char)); - strcpy(igp->i_field, field); + if (igp == NULL) + errx(1, "Out of memory"); + igp->i_field = strdup(field); + if (igp->i_field == NULL) + errx(1, "Out of memory"); igp->i_link = tab->i_head[h]; tab->i_head[h] = igp; tab->i_count++; diff --git a/usr.bin/mail/cmd3.c b/usr.bin/mail/cmd3.c index f9eee9df8a4..bddc3c8e66f 100644 --- a/usr.bin/mail/cmd3.c +++ b/usr.bin/mail/cmd3.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd3.c,v 1.17 2001/11/21 15:26:39 millert Exp $ */ +/* $OpenBSD: cmd3.c,v 1.18 2001/11/21 20:41:55 millert Exp $ */ /* $NetBSD: cmd3.c,v 1.8 1997/07/09 05:29:49 mikel Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static const char sccsid[] = "@(#)cmd3.c 8.2 (Berkeley) 4/20/95"; #else -static const char rcsid[] = "$OpenBSD: cmd3.c,v 1.17 2001/11/21 15:26:39 millert Exp $"; +static const char rcsid[] = "$OpenBSD: cmd3.c,v 1.18 2001/11/21 20:41:55 millert Exp $"; #endif #endif /* not lint */ @@ -265,6 +265,7 @@ char * reedit(char *subj) { char *newsubj; + size_t len; if (subj == NULL) return(NULL); @@ -272,9 +273,10 @@ reedit(char *subj) (subj[1] == 'e' || subj[1] == 'E') && subj[2] == ':') return(subj); - newsubj = salloc(strlen(subj) + 5); - strcpy(newsubj, "Re: "); - strcpy(newsubj + 4, subj); + len = strlen(subj) + 5; + newsubj = salloc(len); + strlcpy(newsubj, "Re: ", len); + strlcat(newsubj, subj, len); return(newsubj); } @@ -489,7 +491,8 @@ group(void *v) gname = *argv; h = hash(gname); if ((gh = findgroup(gname)) == NULL) { - gh = (struct grouphead *)calloc(sizeof(*gh), 1); + if ((gh = (struct grouphead *)calloc(sizeof(*gh), 1)) == NULL) + errx(1, "Out of memory"); gh->g_name = vcopy(gname); gh->g_list = NULL; gh->g_link = groups[h]; @@ -503,7 +506,8 @@ group(void *v) */ for (ap = argv+1; *ap != NULL; ap++) { - gp = (struct group *)calloc(sizeof(*gp), 1); + if ((gp = (struct group *)calloc(sizeof(*gp), 1)) == NULL) + errx(1, "Out of memory"); gp->ge_name = vcopy(*ap); gp->ge_link = gh->g_list; gh->g_list = gp; @@ -719,7 +723,7 @@ int alternates(void *v) { char **namelist = v; - char **ap, **ap2, *cp; + char **ap, **ap2; int c; c = argcount(namelist) + 1; @@ -733,11 +737,11 @@ alternates(void *v) } if (altnames != 0) (void)free(altnames); - altnames = (char **)calloc(c, sizeof(char *)); + if ((altnames = (char **)calloc(c, sizeof(char *))) == NULL) + errx(1, "Out of memory"); for (ap = namelist, ap2 = altnames; *ap; ap++, ap2++) { - cp = (char *)calloc(strlen(*ap) + 1, sizeof(char)); - strcpy(cp, *ap); - *ap2 = cp; + if ((*ap2 = strdup(*ap)) == NULL) + errx(1, "Out of memory"); } *ap2 = 0; return(0); diff --git a/usr.bin/mail/lex.c b/usr.bin/mail/lex.c index 3f1643a5651..aea3fb8b671 100644 --- a/usr.bin/mail/lex.c +++ b/usr.bin/mail/lex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lex.c,v 1.26 2001/11/21 15:26:39 millert Exp $ */ +/* $OpenBSD: lex.c,v 1.27 2001/11/21 20:41:55 millert Exp $ */ /* $NetBSD: lex.c,v 1.10 1997/05/17 19:55:13 pk Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static const char sccsid[] = "@(#)lex.c 8.2 (Berkeley) 4/20/95"; #else -static const char rcsid[] = "$OpenBSD: lex.c,v 1.26 2001/11/21 15:26:39 millert Exp $"; +static const char rcsid[] = "$OpenBSD: lex.c,v 1.27 2001/11/21 20:41:55 millert Exp $"; #endif #endif /* not lint */ @@ -132,7 +132,7 @@ setfile(char *name) } shudclob = 1; edit = isedit; - strcpy(prevfile, mailname); + strlcpy(prevfile, mailname, PATHSIZE); if (name != mailname) strlcpy(mailname, name, sizeof(mailname)); mailsize = fsize(ibuf); @@ -536,12 +536,14 @@ out: * lists to message list functions. */ void -setmsize(int sz) +setmsize(int n) { + size_t msize; - if (msgvec != 0) - (void)free(msgvec); - msgvec = (int *)calloc(sz + 1, sizeof(*msgvec)); + msize = (n + 1) * sizeof(*msgvec); + if ((msgvec = realloc(msgvec, msize)) == NULL) + errx(1, "Out of memory"); + memset(msgvec, 0, msize); } /* diff --git a/usr.bin/mail/list.c b/usr.bin/mail/list.c index 04375fb28d4..9b0fcccdc2e 100644 --- a/usr.bin/mail/list.c +++ b/usr.bin/mail/list.c @@ -1,4 +1,4 @@ -/* $OpenBSD: list.c,v 1.11 2001/11/21 15:26:39 millert Exp $ */ +/* $OpenBSD: list.c,v 1.12 2001/11/21 20:41:55 millert Exp $ */ /* $NetBSD: list.c,v 1.7 1997/07/09 05:23:36 mikel Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static const char sccsid[] = "@(#)list.c 8.4 (Berkeley) 5/1/95"; #else -static const char rcsid[] = "$OpenBSD: list.c,v 1.11 2001/11/21 15:26:39 millert Exp $"; +static const char rcsid[] = "$OpenBSD: list.c,v 1.12 2001/11/21 20:41:55 millert Exp $"; #endif #endif /* not lint */ @@ -513,7 +513,7 @@ scan(char **sp) int quotec; if (regretp >= 0) { - strcpy(lexstring, string_stack[regretp]); + strlcpy(lexstring, string_stack[regretp], STRINGLEN); lexnumber = numberstack[regretp]; return(regretstack[regretp--]); } diff --git a/usr.bin/mail/names.c b/usr.bin/mail/names.c index 15ffb7d334f..26bb61817fe 100644 --- a/usr.bin/mail/names.c +++ b/usr.bin/mail/names.c @@ -1,4 +1,4 @@ -/* $OpenBSD: names.c,v 1.15 2001/11/21 18:43:27 millert Exp $ */ +/* $OpenBSD: names.c,v 1.16 2001/11/21 20:41:55 millert Exp $ */ /* $NetBSD: names.c,v 1.5 1996/06/08 19:48:32 christos Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static const char sccsid[] = "@(#)names.c 8.1 (Berkeley) 6/6/93"; #else -static const char rcsid[] = "$OpenBSD: names.c,v 1.15 2001/11/21 18:43:27 millert Exp $"; +static const char rcsid[] = "$OpenBSD: names.c,v 1.16 2001/11/21 20:41:55 millert Exp $"; #endif #endif /* not lint */ @@ -670,8 +670,7 @@ delname(struct name *np, char *name) */ #if 0 void -prettyprint(name) - struct name *name; +prettyprint(struct name *name) { struct name *np; diff --git a/usr.bin/mail/popen.c b/usr.bin/mail/popen.c index 33961df1dbc..30ab4d9dedb 100644 --- a/usr.bin/mail/popen.c +++ b/usr.bin/mail/popen.c @@ -1,4 +1,4 @@ -/* $OpenBSD: popen.c,v 1.29 2001/11/21 15:26:39 millert Exp $ */ +/* $OpenBSD: popen.c,v 1.30 2001/11/21 20:41:55 millert Exp $ */ /* $NetBSD: popen.c,v 1.6 1997/05/13 06:48:42 mikel Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static const char sccsid[] = "@(#)popen.c 8.1 (Berkeley) 6/6/93"; #else -static const char rcsid[] = "$OpenBSD: popen.c,v 1.29 2001/11/21 15:26:39 millert Exp $"; +static const char rcsid[] = "$OpenBSD: popen.c,v 1.30 2001/11/21 20:41:55 millert Exp $"; #endif #endif /* not lint */ @@ -331,8 +331,11 @@ findchild(pid_t pid, int dont_alloc) if (child_freelist) { *cpp = child_freelist; child_freelist = (*cpp)->link; - } else + } else { *cpp = (struct child *)malloc(sizeof(struct child)); + if (*cpp == NULL) + errx(1, "Out of memory"); + } (*cpp)->pid = pid; (*cpp)->done = (*cpp)->free = 0; (*cpp)->link = NULL; diff --git a/usr.bin/mail/tty.c b/usr.bin/mail/tty.c index e0b344adb12..69fd60d6fbf 100644 --- a/usr.bin/mail/tty.c +++ b/usr.bin/mail/tty.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tty.c,v 1.14 2001/11/21 15:26:39 millert Exp $ */ +/* $OpenBSD: tty.c,v 1.15 2001/11/21 20:41:56 millert Exp $ */ /* $NetBSD: tty.c,v 1.7 1997/07/09 05:25:46 mikel Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static const char sccsid[] = "@(#)tty.c 8.2 (Berkeley) 4/20/95"; #else -static const char rcsid[] = "$OpenBSD: tty.c,v 1.14 2001/11/21 15:26:39 millert Exp $"; +static const char rcsid[] = "$OpenBSD: tty.c,v 1.15 2001/11/21 20:41:56 millert Exp $"; #endif #endif /* not lint */ @@ -201,7 +201,7 @@ readtty(char *pr, char *src) } #ifndef TIOCSTI if (src != NULL) - cp = copy(src, canonb); + cp = copy(src, canonb); /* safe, bounds checked above */ else cp = copy("", canonb); fputs(canonb, stdout); diff --git a/usr.bin/mail/vars.c b/usr.bin/mail/vars.c index a4477122a54..e79ceda8099 100644 --- a/usr.bin/mail/vars.c +++ b/usr.bin/mail/vars.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vars.c,v 1.7 2001/11/21 15:26:39 millert Exp $ */ +/* $OpenBSD: vars.c,v 1.8 2001/11/21 20:41:56 millert Exp $ */ /* $NetBSD: vars.c,v 1.4 1996/06/08 19:48:45 christos Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static const char sccsid[] = "@(#)vars.c 8.1 (Berkeley) 6/6/93"; #else -static const char rcsid[] = "$OpenBSD: vars.c,v 1.7 2001/11/21 15:26:39 millert Exp $"; +static const char rcsid[] = "$OpenBSD: vars.c,v 1.8 2001/11/21 20:41:56 millert Exp $"; #endif #endif /* not lint */ @@ -63,7 +63,8 @@ assign(char *name, char *value) h = hash(name); vp = lookup(name); if (vp == NULL) { - vp = (struct var *)calloc(sizeof(*vp), 1); + if ((vp = (struct var *)calloc(sizeof(*vp), 1)) == NULL) + errx(1, "Out of memory"); vp->v_name = vcopy(name); vp->v_link = variables[h]; variables[h] = vp; |