From dfabf3efaa795e657f3858b7e2d0b11f8a51ecb5 Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Sat, 3 Feb 2024 21:22:09 -0500 Subject: [PATCH] libjail: Guard against programmer error in jailparam_export() If the caller didn't use jailparam_import() to fetch the parameter value, an attempt to export it will trigger a segfault. Make it a bit easier to figure out what's happening in this situation. PR: 276809 Reviewed by: jamie MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D43732 --- lib/libjail/jail.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/libjail/jail.c b/lib/libjail/jail.c index 864c6981db2bed..8e5b420d677bf3 100644 --- a/lib/libjail/jail.c +++ b/lib/libjail/jail.c @@ -737,6 +737,12 @@ jailparam_export(struct jailparam *jp) int i, nval, ival; char valbuf[INET6_ADDRSTRLEN]; + if (jp->jp_value == NULL) { + snprintf(jail_errmsg, JAIL_ERRMSGLEN, + "parameter %s was not imported", jp->jp_name); + errno = EINVAL; + return (NULL); + } if ((jp->jp_ctltype & CTLTYPE) == CTLTYPE_STRING) { value = strdup(jp->jp_value); if (value == NULL)