mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-31 02:00:14 +01:00
glib-aux: merge branch 'th/fix-ifname-valid-kernel'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1692
This commit is contained in:
commit
d441f846b2
3 changed files with 77 additions and 16 deletions
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include "libnm-core-impl/nm-default-libnm-core.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
|
@ -87,21 +88,65 @@ G_STATIC_ASSERT(NM_UTILS_HWADDR_LEN_MAX == _NM_UTILS_HWADDR_LEN_MAX);
|
|||
static void
|
||||
test_nm_ascii_spaces(void)
|
||||
{
|
||||
int i;
|
||||
const char *const S = NM_ASCII_SPACES;
|
||||
int i;
|
||||
|
||||
for (i = 0; S[i]; i++)
|
||||
g_assert(!strchr(&S[i + 1], S[i]));
|
||||
{
|
||||
const char *const S = NM_ASCII_SPACES;
|
||||
|
||||
for (i = 0; S[i] != '\0'; i++)
|
||||
g_assert(g_ascii_isspace(S[i]));
|
||||
for (i = 0; S[i]; i++)
|
||||
g_assert(!strchr(&S[i + 1], S[i]));
|
||||
|
||||
g_assert(!g_ascii_isspace((char) 0));
|
||||
for (i = 1; i < 0x100; i++) {
|
||||
if (g_ascii_isspace((char) i))
|
||||
g_assert(strchr(S, (char) i));
|
||||
else
|
||||
g_assert(!strchr(S, (char) i));
|
||||
for (i = 0; S[i] != '\0'; i++)
|
||||
g_assert(g_ascii_isspace(S[i]));
|
||||
|
||||
g_assert(!g_ascii_isspace((char) 0));
|
||||
for (i = 1; i < 0x100; i++) {
|
||||
g_assert((!!g_ascii_isspace((char) i)) == (!!strchr(S, (char) i)));
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const char *const S = NM_ASCII_WHITESPACES;
|
||||
|
||||
for (i = 0; S[i]; i++)
|
||||
g_assert(!strchr(&S[i + 1], S[i]));
|
||||
|
||||
for (i = 0; S[i] != '\0'; i++)
|
||||
g_assert(nm_ascii_is_whitespace(S[i]));
|
||||
|
||||
g_assert(!nm_ascii_is_whitespace((char) 0));
|
||||
for (i = 1; i < 0x100; i++) {
|
||||
g_assert(nm_ascii_is_whitespace((char) i) == (!!strchr(S, (char) i)));
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const char *const S = NM_ASCII_SPACES_CTYPE;
|
||||
|
||||
for (i = 0; S[i]; i++)
|
||||
g_assert(!strchr(&S[i + 1], S[i]));
|
||||
|
||||
if (nm_streq0(g_getenv("LANG"), "C")) {
|
||||
g_assert(!isspace((char) 0));
|
||||
for (i = 1; i < 0x100; i++) {
|
||||
g_assert((!!isspace((char) i)) == (!!strchr(S, (char) i)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const char *const S = NM_ASCII_SPACES_KERNEL;
|
||||
|
||||
for (i = 0; S[i]; i++)
|
||||
g_assert(!strchr(&S[i + 1], S[i]));
|
||||
|
||||
for (i = 0; S[i] != '\0'; i++)
|
||||
g_assert(nm_ascii_is_space_kernel(S[i]));
|
||||
|
||||
g_assert(!nm_ascii_is_space_kernel((char) 0));
|
||||
for (i = 1; i < 0x100; i++) {
|
||||
g_assert(nm_ascii_is_space_kernel((char) i) == (!!strchr(S, (char) i)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1086,11 +1086,20 @@ nm_g_variant_equal(GVariant *a, GVariant *b)
|
|||
/* mirrors g_ascii_isspace() and what we consider spaces in general. */
|
||||
#define NM_ASCII_SPACES " \n\t\r\f"
|
||||
|
||||
/* Like NM_ASCII_SPACES, but without "\f" (0x0c, Formfeed Page Break).
|
||||
* This is what for example systemd calls WHITESPACE and what it uses to tokenize
|
||||
* the kernel command line. */
|
||||
/* Like NM_ASCII_SPACES, but without "\f" (0x0c, Formfeed Page Break). This is
|
||||
* what for example systemd calls WHITESPACE and what it uses to tokenize the
|
||||
* kernel command line. */
|
||||
#define NM_ASCII_WHITESPACES " \n\t\r"
|
||||
|
||||
/* mirrors <ctype.h>'s isspace() with C locale. It's like NM_ASCII_SPACES but
|
||||
* additionally also considers '\v' (vertical tab). */
|
||||
#define NM_ASCII_SPACES_CTYPE NM_ASCII_SPACES "\v"
|
||||
|
||||
/* mirrors kernel's isspace() from "include/linux/ctype.h", which treats as
|
||||
* space the common ASCII spaces, including '\v' (vertical tab), but also
|
||||
* '\240' (non-breaking space, NBSP in Latin-1). */
|
||||
#define NM_ASCII_SPACES_KERNEL NM_ASCII_SPACES_CTYPE "\240"
|
||||
|
||||
static inline gboolean
|
||||
nm_ascii_is_whitespace(char ch)
|
||||
{
|
||||
|
|
@ -1100,6 +1109,13 @@ nm_ascii_is_whitespace(char ch)
|
|||
return NM_IN_SET(ch, ' ', '\n', '\t', '\r');
|
||||
}
|
||||
|
||||
static inline gboolean
|
||||
nm_ascii_is_space_kernel(char ch)
|
||||
{
|
||||
/* Checks whether @ch is in NM_ASCII_SPACES_KERNEL. */
|
||||
return NM_IN_SET(ch, ' ', '\n', '\t', '\r', '\f', '\v', '\240');
|
||||
}
|
||||
|
||||
#define NM_ASCII_NEWLINE "\n\r"
|
||||
|
||||
static inline gboolean
|
||||
|
|
|
|||
|
|
@ -5352,7 +5352,7 @@ nm_utils_ifname_valid_kernel(const char *name, GError **error)
|
|||
|
||||
if (ch == '\0')
|
||||
return TRUE;
|
||||
if (NM_IN_SET(ch, '/', ':') || g_ascii_isspace(ch)) {
|
||||
if (NM_IN_SET(ch, '/', ':') || nm_ascii_is_space_kernel(ch)) {
|
||||
g_set_error_literal(error,
|
||||
NM_UTILS_ERROR,
|
||||
NM_UTILS_ERROR_UNKNOWN,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue