musl: hostname-util: introduce LINUX_HOST_NAME_MAX
glibc defines HOST_NAME_MAX as 64 and our code rely on that, but musl defines the constant as 255. Let's provide our own definition for the maximum length.
This commit is contained in:
@@ -94,8 +94,8 @@ bool hostname_is_valid(const char *s, ValidHostnameFlags flags) {
|
||||
if (hyphen)
|
||||
return false;
|
||||
|
||||
if (p-s > HOST_NAME_MAX) /* Note that HOST_NAME_MAX is 64 on Linux, but DNS allows domain names up to
|
||||
* 255 characters */
|
||||
/* Note that host name max is 64 on Linux, but DNS allows domain names up to 255 characters. */
|
||||
if (p - s > (ssize_t) LINUX_HOST_NAME_MAX)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@@ -107,7 +107,7 @@ char* hostname_cleanup(char *s) {
|
||||
|
||||
assert(s);
|
||||
|
||||
for (p = s, d = s, dot = hyphen = true; *p && d - s < HOST_NAME_MAX; p++)
|
||||
for (p = s, d = s, dot = hyphen = true; *p && d - s < (ssize_t) LINUX_HOST_NAME_MAX; p++)
|
||||
if (*p == '.') {
|
||||
if (dot || hyphen)
|
||||
continue;
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
#include "basic-forward.h"
|
||||
#include "strv.h"
|
||||
|
||||
/* HOST_NAME_MAX should be 64 on linux, but musl uses the one by POSIX (255). */
|
||||
#define LINUX_HOST_NAME_MAX CONST_MIN((size_t) HOST_NAME_MAX, (size_t) 64)
|
||||
|
||||
char* get_default_hostname_raw(void);
|
||||
|
||||
bool valid_ldh_char(char c) _const_;
|
||||
|
||||
Reference in New Issue
Block a user