mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-03 02:20:14 +01:00
utils: add nm_utils_is_valid_path_component()
(cherry picked from commit 633deb0a98)
This commit is contained in:
parent
30768c7240
commit
c5569a4e11
2 changed files with 16 additions and 8 deletions
|
|
@ -2681,28 +2681,35 @@ nm_utils_ip4_property_path (const char *ifname, const char *property)
|
|||
return _get_property_path (ifname, property, FALSE);
|
||||
}
|
||||
|
||||
const char *
|
||||
ASSERT_VALID_PATH_COMPONENT (const char *name)
|
||||
gboolean
|
||||
nm_utils_is_valid_path_component (const char *name)
|
||||
{
|
||||
const char *n;
|
||||
|
||||
if (name == NULL || name[0] == '\0')
|
||||
goto fail;
|
||||
return FALSE;
|
||||
|
||||
if (name[0] == '.') {
|
||||
if (name[1] == '\0')
|
||||
goto fail;
|
||||
return FALSE;
|
||||
if (name[1] == '.' && name[2] == '\0')
|
||||
goto fail;
|
||||
return FALSE;
|
||||
}
|
||||
n = name;
|
||||
do {
|
||||
if (*n == '/')
|
||||
goto fail;
|
||||
return FALSE;
|
||||
} while (*(++n) != '\0');
|
||||
|
||||
return name;
|
||||
fail:
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
const char *
|
||||
ASSERT_VALID_PATH_COMPONENT (const char *name)
|
||||
{
|
||||
if (G_LIKELY (nm_utils_is_valid_path_component (name)))
|
||||
return name;
|
||||
|
||||
nm_log_err (LOGD_CORE, "Failed asserting path component: %s%s%s",
|
||||
NM_PRINT_FMT_QUOTED (name, "\"", name, "\"", "(null)"));
|
||||
g_error ("FATAL: Failed asserting path component: %s%s%s",
|
||||
|
|
|
|||
|
|
@ -163,6 +163,7 @@ gint64 nm_utils_get_monotonic_timestamp_ms (void);
|
|||
gint32 nm_utils_get_monotonic_timestamp_s (void);
|
||||
gint64 nm_utils_monotonic_timestamp_as_boottime (gint64 timestamp, gint64 timestamp_ticks_per_ns);
|
||||
|
||||
gboolean nm_utils_is_valid_path_component (const char *name);
|
||||
const char *ASSERT_VALID_PATH_COMPONENT (const char *name);
|
||||
const char *nm_utils_ip6_property_path (const char *ifname, const char *property);
|
||||
const char *nm_utils_ip4_property_path (const char *ifname, const char *property);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue