The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=7e70589b1bee4853cb11e3d8eb963079b18ff534
commit 7e70589b1bee4853cb11e3d8eb963079b18ff534 Author: Kyle Evans <[email protected]> AuthorDate: 2026-03-03 22:51:01 +0000 Commit: Kyle Evans <[email protected]> CommitDate: 2026-03-03 22:51:01 +0000 libutil: take a size_t in trimdomain() INT_MAX is already larger than a reasonable hostname might be, but size_t makes some of this easier to reason about as we do arithmetic with it. This would maybe not be worth it if we had to bump the soversion because of it, but libutil does symbol versioning now so we can provide a compat shim. While we're here, fix some inconsistencies in argument names in the manpage. Reviewed by: des Obtained from: https://github.com/apple-oss-distributions/libutil Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D54622 --- lib/libutil/Symbol.map | 5 ++++- lib/libutil/libutil.h | 2 +- lib/libutil/trimdomain.3 | 8 ++++---- lib/libutil/trimdomain.c | 18 +++++++++++++++++- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/lib/libutil/Symbol.map b/lib/libutil/Symbol.map index 2b28456f4406..fbd10769b2a0 100644 --- a/lib/libutil/Symbol.map +++ b/lib/libutil/Symbol.map @@ -115,7 +115,6 @@ FBSD_1.8 { setclassenvironment; setclassresources; setusercontext; - trimdomain; uu_lock_txfr; uu_lock; uu_lockerr; @@ -130,6 +129,10 @@ FBSD_1.8 { crypt_set_format; }; +FBSD_1.9 { + trimdomain; +}; + FBSDprivate_1.0 { __pw_initpwd; }; diff --git a/lib/libutil/libutil.h b/lib/libutil/libutil.h index 9b5b2abe7f09..17e4f1fba247 100644 --- a/lib/libutil/libutil.h +++ b/lib/libutil/libutil.h @@ -140,7 +140,7 @@ int realhostname(char *_host, size_t _hsize, const struct in_addr *_ip); int realhostname_sa(char *_host, size_t _hsize, struct sockaddr *_addr, int _addrlen); int _secure_path(const char *_path, uid_t _uid, gid_t _gid); -void trimdomain(char *_fullhost, int _hostsize); +void trimdomain(char *_fullhost, size_t _hostsize); const char * uu_lockerr(int _uu_lockresult); int uu_lock(const char *_ttyname); diff --git a/lib/libutil/trimdomain.3 b/lib/libutil/trimdomain.3 index 114d8d139869..4a3a4d5827ec 100644 --- a/lib/libutil/trimdomain.3 +++ b/lib/libutil/trimdomain.3 @@ -22,7 +22,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd February 17, 2025 +.Dd March 3, 2026 .Dt TRIMDOMAIN 3 .Os .Sh NAME @@ -34,7 +34,7 @@ .In sys/types.h .In libutil.h .Ft void -.Fn trimdomain "char *fullhost" "int hostsize" +.Fn trimdomain "char *fullhost" "size_t hostsize" .Sh DESCRIPTION The function .Fn trimdomain @@ -53,13 +53,13 @@ the first time this function is called and is cached for future use. The .Fn trimdomain function will only trim the domain name if the passed -.Ar fullname +.Ar fullhost ends with the current domain name and if the length of the resulting host name does not exceed .Ar hostsize . .Pp If the passed -.Ar fullname +.Ar fullhost is actually an X11 .Ev DISPLAY specification of the form diff --git a/lib/libutil/trimdomain.c b/lib/libutil/trimdomain.c index 77518a389419..47297817a76f 100644 --- a/lib/libutil/trimdomain.c +++ b/lib/libutil/trimdomain.c @@ -34,6 +34,7 @@ #include <string.h> #include <unistd.h> +void freebsd15_trimdomain(char *, int); static int isDISP(const char *); /*- @@ -50,7 +51,7 @@ static int isDISP(const char *); * trimdomain("abcde.my.domain:0.0", 8) -> "abcde.my.domain:0.0" */ void -trimdomain(char *fullhost, int hostsize) +trimdomain(char *fullhost, size_t hostsize) { static size_t dlen; static int first = 1; @@ -89,6 +90,21 @@ trimdomain(char *fullhost, int hostsize) } } +void +freebsd15_trimdomain(char *fullhost, int hostsize) +{ + /* + * Note that we intentionally aren't doing anything here about a + * negative `hostsize`, to preserve historical behavior. Functionally, + * it would have ended up as a very large size passing to the memchr(3), + * thus either appearing to work or reading off the end of the buffer if + * `fullhost` is actually malformed. + */ + trimdomain(fullhost, hostsize); +} + +__sym_compat(trimdomain, freebsd15_trimdomain, FBSD_1.8); + /* * Is the given string NN or NN.NN where ``NN'' is an all-numeric string ? */
