From accd6aa25eb53de2f351ce0acf10a45a97723506 Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Tue, 7 Jan 2020 21:44:27 +0000 Subject: [PATCH] libjail: Handle an error from reallocarray() when trimming the buffer. There is no API guarantee that realloc() will not fail when the buffer is shrinking. Handle it by simply returning the untrimmed buffer. While this is unlikely to ever happen in practice, it seems worth handling just to silence static analyzer warnings. PR: 243106 Submitted by: Hans Christian Woithe MFC after: 1 week --- lib/libjail/jail.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/libjail/jail.c b/lib/libjail/jail.c index 6a35cdc6dde5..3e0c2a0f98cb 100644 --- a/lib/libjail/jail.c +++ b/lib/libjail/jail.c @@ -262,7 +262,10 @@ jailparam_all(struct jailparam **jpp) goto error; mib1[1] = 2; } - jp = reallocarray(jp, njp, sizeof(*jp)); + /* Just return the untrimmed buffer if reallocarray() somehow fails. */ + tjp = reallocarray(jp, njp, sizeof(*jp)); + if (tjp != NULL) + jp = tjp; *jpp = jp; return (njp);