platform: move asserts for sysctl_get/set functions to nm-linux-platform
Also assert inside of sysctl_get() that we read the expected file locations. Especially because now we might log the content of these files. Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
@@ -1462,6 +1462,12 @@ sysctl_set (NMPlatform *platform, const char *path, const char *value)
|
||||
g_return_val_if_fail (path != NULL, FALSE);
|
||||
g_return_val_if_fail (value != NULL, FALSE);
|
||||
|
||||
/* Don't write outside known locations */
|
||||
g_assert (g_str_has_prefix (path, "/proc/sys/")
|
||||
|| g_str_has_prefix (path, "/sys/"));
|
||||
/* Don't write to suspicious locations */
|
||||
g_assert (!strstr (path, "/.."));
|
||||
|
||||
fd = open (path, O_WRONLY | O_TRUNC);
|
||||
if (fd == -1) {
|
||||
if (errno == ENOENT) {
|
||||
@@ -1555,6 +1561,12 @@ sysctl_get (NMPlatform *platform, const char *path)
|
||||
GError *error = NULL;
|
||||
char *contents;
|
||||
|
||||
/* Don't write outside known locations */
|
||||
g_assert (g_str_has_prefix (path, "/proc/sys/")
|
||||
|| g_str_has_prefix (path, "/sys/"));
|
||||
/* Don't write to suspicious locations */
|
||||
g_assert (!strstr (path, "/.."));
|
||||
|
||||
if (!g_file_get_contents (path, &contents, NULL, &error)) {
|
||||
/* We assume FAILED means EOPNOTSUP */
|
||||
if ( g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT)
|
||||
|
Reference in New Issue
Block a user