Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 7 May 2017 01:28:53 +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-11@freebsd.org
Subject:   svn commit: r317893 - stable/11/lib/libjail
Message-ID:  <201705070128.v471Srh4058176@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: pfg
Date: Sun May  7 01:28:52 2017
New Revision: 317893
URL: https://svnweb.freebsd.org/changeset/base/317893

Log:
  MFC r317036:
  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

Modified:
  stable/11/lib/libjail/jail.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/lib/libjail/jail.c
==============================================================================
--- stable/11/lib/libjail/jail.c	Sun May  7 00:26:57 2017	(r317892)
+++ stable/11/lib/libjail/jail.c	Sun May  7 01:28:52 2017	(r317893)
@@ -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];
 
@@ -245,7 +245,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;
@@ -254,7 +254,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);
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201705070128.v471Srh4058176>