diff options
author | pfg <pfg@FreeBSD.org> | 2017-05-07 01:28:52 +0000 |
---|---|---|
committer | pfg <pfg@FreeBSD.org> | 2017-05-07 01:28:52 +0000 |
commit | cca5af1b9cc197e4953c52bd73cf0d77e87c7484 (patch) | |
tree | c5254f83d7c9397c677738dbe70e54f390616846 /lib | |
parent | 43f0562b08c8c99ba21e96b92f9f8facdba5020a (diff) | |
download | FreeBSD-src-cca5af1b9cc197e4953c52bd73cf0d77e87c7484.zip FreeBSD-src-cca5af1b9cc197e4953c52bd73cf0d77e87c7484.tar.gz |
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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libjail/jail.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/libjail/jail.c b/lib/libjail/jail.c index 0edfb3f..db0771e 100644 --- a/lib/libjail/jail.c +++ b/lib/libjail/jail.c @@ -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); |