core: add ASSERT_VALID_PATH_COMPONENT function
Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
@@ -1052,3 +1052,35 @@ nm_utils_ip6_property_path (const char *ifname, const char *property)
|
|||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
ASSERT_VALID_PATH_COMPONENT (const char *name)
|
||||||
|
{
|
||||||
|
const char *n;
|
||||||
|
|
||||||
|
if (name == NULL || name[0] == '\0')
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
if (name[0] == '.') {
|
||||||
|
if (name[1] == '\0')
|
||||||
|
goto fail;
|
||||||
|
if (name[1] == '.' && name[2] == '\0')
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
n = name;
|
||||||
|
do {
|
||||||
|
if (*n == '/')
|
||||||
|
goto fail;
|
||||||
|
} while (*(++n) != '\0');
|
||||||
|
|
||||||
|
return name;
|
||||||
|
fail:
|
||||||
|
if (name)
|
||||||
|
nm_log_err (LOGD_CORE, "Failed asserting path component: NULL");
|
||||||
|
else
|
||||||
|
nm_log_err (LOGD_CORE, "Failed asserting path component: \"%s\"", name);
|
||||||
|
g_assert_not_reached ();
|
||||||
|
g_return_val_if_reached ("XXXXX");
|
||||||
|
return "XXXXX";
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -108,6 +108,7 @@ gint64 nm_utils_get_monotonic_timestamp_us (void);
|
|||||||
gint64 nm_utils_get_monotonic_timestamp_ms (void);
|
gint64 nm_utils_get_monotonic_timestamp_ms (void);
|
||||||
gint32 nm_utils_get_monotonic_timestamp_s (void);
|
gint32 nm_utils_get_monotonic_timestamp_s (void);
|
||||||
|
|
||||||
|
const char *ASSERT_VALID_PATH_COMPONENT (const char *name) G_GNUC_WARN_UNUSED_RESULT;
|
||||||
const char *nm_utils_ip6_property_path (const char *ifname, const char *property);
|
const char *nm_utils_ip6_property_path (const char *ifname, const char *property);
|
||||||
|
|
||||||
#endif /* NETWORK_MANAGER_UTILS_H */
|
#endif /* NETWORK_MANAGER_UTILS_H */
|
||||||
|
Reference in New Issue
Block a user