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
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 ?
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user