Date: Sun, 17 Jul 2016 18:32:33 +0000 (UTC) From: "Pedro F. Giffuni" <pfg@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r302968 - stable/10/usr.bin/mail Message-ID: <201607171832.u6HIWXGC033972@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: pfg Date: Sun Jul 17 18:32:33 2016 New Revision: 302968 URL: https://svnweb.freebsd.org/changeset/base/302968 Log: MFC r302511, r302771, r302845: mail(1): check for out of memory conditions when calling calloc(3). Modified: stable/10/usr.bin/mail/cmd3.c stable/10/usr.bin/mail/vars.c Directory Properties: stable/10/ (props changed) Modified: stable/10/usr.bin/mail/cmd3.c ============================================================================== --- stable/10/usr.bin/mail/cmd3.c Sun Jul 17 18:23:20 2016 (r302967) +++ stable/10/usr.bin/mail/cmd3.c Sun Jul 17 18:32:33 2016 (r302968) @@ -463,7 +463,8 @@ group(char **argv) gname = *argv; h = hash(gname); if ((gh = findgroup(gname)) == NULL) { - gh = calloc(sizeof(*gh), 1); + if ((gh = calloc(1, sizeof(*gh))) == NULL) + err(1, "Out of memory"); gh->g_name = vcopy(gname); gh->g_list = NULL; gh->g_link = groups[h]; @@ -477,7 +478,8 @@ group(char **argv) */ for (ap = argv+1; *ap != NULL; ap++) { - gp = calloc(sizeof(*gp), 1); + if ((gp = calloc(1, sizeof(*gp))) == NULL) + err(1, "Out of memory"); gp->ge_name = vcopy(*ap); gp->ge_link = gh->g_list; gh->g_list = gp; @@ -702,7 +704,8 @@ alternates(char **namelist) } if (altnames != 0) (void)free(altnames); - altnames = calloc((unsigned)c, sizeof(char *)); + if ((altnames = calloc((unsigned)c, sizeof(char *))) == NULL) + err(1, "Out of memory"); for (ap = namelist, ap2 = altnames; *ap != NULL; ap++, ap2++) { cp = calloc((unsigned)strlen(*ap) + 1, sizeof(char)); strcpy(cp, *ap); Modified: stable/10/usr.bin/mail/vars.c ============================================================================== --- stable/10/usr.bin/mail/vars.c Sun Jul 17 18:23:20 2016 (r302967) +++ stable/10/usr.bin/mail/vars.c Sun Jul 17 18:32:33 2016 (r302968) @@ -56,7 +56,8 @@ assign(const char *name, const char *val h = hash(name); vp = lookup(name); if (vp == NULL) { - vp = calloc(sizeof(*vp), 1); + if ((vp = calloc(1, sizeof(*vp))) == NULL) + err(1, "Out of memory"); vp->v_name = vcopy(name); vp->v_link = variables[h]; variables[h] = vp;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201607171832.u6HIWXGC033972>