1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-02-09 09:57:26 +03:00

cgroups-show: validate specified hostname before including it in fs path

let's make sure the specified hostname is really valid before we build
an fs path from it. Just as a safety future, so that people can't trick
us with hostnames including "/../" or so.
This commit is contained in:
Lennart Poettering 2021-10-06 17:04:16 +02:00
parent a5edf95ec2
commit 40d4320dea

View File

@ -14,6 +14,7 @@
#include "env-file.h"
#include "fd-util.h"
#include "format-util.h"
#include "hostname-util.h"
#include "locale-util.h"
#include "macro.h"
#include "output-mode.h"
@ -355,14 +356,17 @@ int show_cgroup_get_path_and_warn(
const char *prefix,
char **ret) {
int r;
_cleanup_free_ char *root = NULL;
int r;
if (machine) {
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
_cleanup_free_ char *unit = NULL;
const char *m;
if (!hostname_is_valid(machine, 0))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Machine name is not valid: %s", machine);
m = strjoina("/run/systemd/machines/", machine);
r = parse_env_file(NULL, m, "SCOPE", &unit);
if (r < 0)