From nobody Fri Feb 04 13:10:36 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id E336019A7A66; Fri, 4 Feb 2022 13:10:36 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JqwrX4xWjz3HKL; Fri, 4 Feb 2022 13:10:36 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643980236; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=cHKKg3Pv784P1m8yZUr0riAqScO7JGJKCLCN9Sg9akM=; b=iALRQdgYR9HhJq6/INzETpePwA3q7f6DgkXKEWbVMljy+fxCF8LsPnWk5ZlksPVvtQjZ+R z6crSMo2MWNKQUStvH3ZzTD9+a/hnccRW/dWZHVm8jtcTjsnqQaDz18qCj6npGQLwoNIIG 0MaYkvAB2S1fRD888fiU/md0l18fhIons21HbfghPzmZ0+xLTyvpGbVtI58jgJ8WXeSkNV 6DlZCXTgvgR7/1CfD/OGhzM3av/ET41JxpMaSRCrGqDmFuBxXa6eW3cz84oXGHIhk2U0gU JDDpqXp+KHISL44IYLTmvMElvfsI/S5PsuFf+lq0QZaJfVvKy/yE3F+ko6YWtg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 78B634251; Fri, 4 Feb 2022 13:10:36 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 214DAaRQ054425; Fri, 4 Feb 2022 13:10:36 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 214DAatB054424; Fri, 4 Feb 2022 13:10:36 GMT (envelope-from git) Date: Fri, 4 Feb 2022 13:10:36 GMT Message-Id: <202202041310.214DAatB054424@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: =?utf-8?Q?Stefan E=C3=9Fer?= Subject: git: e11ad014d146 - main - libc: return partial sysctl() result if buffer is too small List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: se X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: e11ad014d1468729ecf758ab3709618a78feae1b Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643980236; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=cHKKg3Pv784P1m8yZUr0riAqScO7JGJKCLCN9Sg9akM=; b=yeedMBm7TBMHEhIna2AIiodeNeB0QQOEwmVeNjL1GwiDHlIlO8vupGOU029fgng1cU5frM Weh1hbihMIq/lMysCbVH5dr1zJbUesmHXGGWxcLuGhZW9Fa0j4WNo9XDywPbLH+gS0nJOk 8i9VVnNT4CVPl4gbR7yKGdqrhf/t4mcyF9uQ6W7SFwQJ9EdWaDke92eWi9wziieKdAAzQF JKnSFQF/H2QpOepMj0tMtDvlEwXxY881FJwd06udGzwbEXnN6EBzrXEKFwfFiPN3gUb+1Z 47Xn6MZ9HXRSpTWj7I96CtgO8So49xygKr/6U51Kok/BOZjPmSwAvWgG3eeKDg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1643980236; a=rsa-sha256; cv=none; b=tAZCBM9HwCceD0sZIsnI2QZ5V+oaN9MvdexJyBSSUADQMspnySOCPq+Ff9vbOb99B8t8wt ic+kFDlYsCoIcvT3lVOx87sbc9OWi66E+8gAqI7RwmKfazLr6a1hyvmpa/GYAzd26uEY8o O3DlMiH7rrcCo5NTQGXgOk04PpQArz3tDXa6FHdwqlOkpXnkq5nFU+iMEKLCD4g30zaWwp KNII+7sQqIxtM7z+V0qP13m/y25tih9XTBqC5O4xc1E7purQ+0B8P13xybqm6dDJDKQUTh TbLA300lNInhet7UIp32lmsHD9vlxjq6qeMbAaVx0gz73sbUNLBLmQi67lW6YQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by se: URL: https://cgit.FreeBSD.org/src/commit/?id=e11ad014d1468729ecf758ab3709618a78feae1b commit e11ad014d1468729ecf758ab3709618a78feae1b Author: Stefan Eßer AuthorDate: 2022-02-04 12:44:20 +0000 Commit: Stefan Eßer CommitDate: 2022-02-04 12:44:20 +0000 libc: return partial sysctl() result if buffer is too small Testing of a new feature revealed that calling sysctl() to retrieve the value of the user.localbase variable passing too low a buffer size could leave the result buffer unchanged. The behavior in the normal case of a sufficiently large buffer was correct. All known callers pass a sufficiently large buffer and have thus not been affected by this issue. If a non-default value had been assigned to this variable, the result was as documented, too. Fix the function to fill the buffer with a partial result, if the passed in buffer size is too low to hold the full result. MFC after: 3 days --- lib/libc/gen/sysctl.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/libc/gen/sysctl.c b/lib/libc/gen/sysctl.c index cdd2d3e391e6..9dd80ddfc0d8 100644 --- a/lib/libc/gen/sysctl.c +++ b/lib/libc/gen/sysctl.c @@ -74,17 +74,18 @@ sysctl(const int *name, u_int namelen, void *oldp, size_t *oldlenp, /* Variables under CLT_USER that may be overridden by kernel values */ switch (name[1]) { case USER_LOCALBASE: - if (oldlenp == NULL || *oldlenp != 1) - return (0); - if (oldp != NULL) { - if (orig_oldlen < sizeof(_PATH_LOCALBASE)) { - errno = ENOMEM; - return (-1); + if (oldlenp != NULL && *oldlenp == 1) { + *oldlenp = sizeof(_PATH_LOCALBASE); + if (oldp != NULL) { + if (*oldlenp > orig_oldlen) { + *oldlenp = orig_oldlen; + errno = ENOMEM; + retval = -1; + } + memmove(oldp, _PATH_LOCALBASE, *oldlenp); } - memmove(oldp, _PATH_LOCALBASE, sizeof(_PATH_LOCALBASE)); } - *oldlenp = sizeof(_PATH_LOCALBASE); - return (0); + return (retval); } /* Variables under CLT_USER whose values are immutably defined below */