Author: pfg
Date: Sun Jul 17 18:23:20 2016
New Revision: 302967
URL: https://svnweb.freebsd.org/changeset/base/302967

Log:
  MFC r302511, r302771, r302845:
  mail(1): check for out of memory conditions when calling calloc(3).
  
  Approved by:  re (gjb)

Modified:
  stable/11/usr.bin/mail/cmd3.c
  stable/11/usr.bin/mail/vars.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/usr.bin/mail/cmd3.c
==============================================================================
--- stable/11/usr.bin/mail/cmd3.c       Sun Jul 17 15:36:02 2016        
(r302966)
+++ stable/11/usr.bin/mail/cmd3.c       Sun Jul 17 18:23:20 2016        
(r302967)
@@ -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/11/usr.bin/mail/vars.c
==============================================================================
--- stable/11/usr.bin/mail/vars.c       Sun Jul 17 15:36:02 2016        
(r302966)
+++ stable/11/usr.bin/mail/vars.c       Sun Jul 17 18:23:20 2016        
(r302967)
@@ -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;
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to