Author: pfg
Date: Sun Apr 16 19:23:10 2017
New Revision: 317036
URL: https://svnweb.freebsd.org/changeset/base/317036

Log:
  libjail: make allocation in jailparam_all() somewhat more robust.
  
  Unsign some variables involved in allocation as they will never be
  negative anyways. Provide some bounds checking through reallocarray(3).
  
  This is all very unlikely to have any visible effect.
  
  Reviewed by:  jamie
  MFC after:    3 weeks

Modified:
  head/lib/libjail/jail.c

Modified: head/lib/libjail/jail.c
==============================================================================
--- head/lib/libjail/jail.c     Sun Apr 16 19:17:10 2017        (r317035)
+++ head/lib/libjail/jail.c     Sun Apr 16 19:23:10 2017        (r317036)
@@ -200,7 +200,7 @@ jailparam_all(struct jailparam **jpp)
 {
        struct jailparam *jp, *tjp;
        size_t mlen1, mlen2, buflen;
-       int njp, nlist;
+       unsigned njp, nlist;
        int mib1[CTL_MAXNAME], mib2[CTL_MAXNAME - 2];
        char buf[MAXPATHLEN];
 
@@ -250,7 +250,7 @@ jailparam_all(struct jailparam **jpp)
                /* Add the parameter to the list */
                if (njp >= nlist) {
                        nlist *= 2;
-                       tjp = realloc(jp, nlist * sizeof(*jp));
+                       tjp = reallocarray(jp, nlist, sizeof(*jp));
                        if (tjp == NULL)
                                goto error;
                        jp = tjp;
@@ -259,7 +259,7 @@ jailparam_all(struct jailparam **jpp)
                        goto error;
                mib1[1] = 2;
        }
-       jp = realloc(jp, njp * sizeof(*jp));
+       jp = reallocarray(jp, njp, sizeof(*jp));
        *jpp = jp;
        return (njp);
 
_______________________________________________
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