Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Leap:42.1
systemd
0001-core-make-unit-deserialization-more-defens...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0001-core-make-unit-deserialization-more-defensive.patch of Package systemd
From e911de996a72af7659e4019f03b80f11c476f3f3 Mon Sep 17 00:00:00 2001 From: Lennart Poettering <lennart@poettering.net> Date: Tue, 21 Apr 2015 20:22:51 +0200 Subject: [PATCH] core: make unit deserialization more defensive --- src/core/unit.c | 59 ++++++++++++++++++++++++++++++++++++++----------- src/shared/time-util.c | 15 +++++++----- src/shared/time-util.h | 2 - 3 files changed, 56 insertions(+), 20 deletions(-) --- src/core/unit.c +++ src/core/unit.c 2015-06-17 09:51:14.637518042 +0000 @@ -2352,6 +2352,40 @@ void unit_serialize_item(Unit *u, FILE * fprintf(f, "%s=%s\n", key, value); } +static int unit_set_cgroup_path(Unit *u, const char *path) { + _cleanup_free_ char *p = NULL; + int r; + + assert(u); + + if (path) { + p = strdup(path); + if (!p) + return -ENOMEM; + } else + p = NULL; + + if (streq_ptr(u->cgroup_path, p)) + return 0; + + if (p) { + r = hashmap_put(u->manager->cgroup_unit, p, u); + if (r < 0) + return r; + } + + if (u->cgroup_path) { + log_debug_unit(u->id, "%s: Changing cgroup path from %s to %s.", u->id, u->cgroup_path, strna(p)); + hashmap_remove(u->manager->cgroup_unit, u->cgroup_path); + free(u->cgroup_path); + } + + u->cgroup_path = p; + p = NULL; + + return 0; +} + int unit_deserialize(Unit *u, FILE *f, FDSet *fds) { ExecRuntime **rt = NULL; size_t offset; @@ -2379,7 +2413,7 @@ int unit_deserialize(Unit *u, FILE *f, F l = strstrip(line); /* End marker */ - if (l[0] == 0) + if (isempty(l)) return 0; k = strcspn(l, "="); @@ -2395,7 +2429,7 @@ int unit_deserialize(Unit *u, FILE *f, F /* new-style serialized job */ Job *j = job_new_raw(u); if (!j) - return -ENOMEM; + return log_oom(); r = job_deserialize(j, f, fds); if (r < 0) { @@ -2464,16 +2498,11 @@ int unit_deserialize(Unit *u, FILE *f, F continue; } else if (streq(l, "cgroup")) { - char *s; - - s = strdup(v); - if (!s) - return -ENOMEM; - free(u->cgroup_path); - u->cgroup_path = s; + r = unit_set_cgroup_path(u, v); + if (r < 0) + log_debug("Failed to set cgroup path %s: %s", v, strerror(-r)); - assert(hashmap_put(u->manager->cgroup_unit, s, u) == 1); continue; } else if (streq(l, "cgroup-realized")) { int b; @@ -2490,15 +2519,19 @@ int unit_deserialize(Unit *u, FILE *f, F if (unit_can_serialize(u)) { if (rt) { r = exec_runtime_deserialize_item(rt, u, l, v, fds); - if (r < 0) - return r; + if (r < 0) { + log_warning_unit(u->id, "Failed to deserialize runtime parameter '%s', ignoring.", l); + continue; + } + + /* Returns positive if key was handled by the call */ if (r > 0) continue; } r = UNIT_VTABLE(u)->deserialize_item(u, l, v, fds); if (r < 0) - return r; + log_warning_unit(u->id, "Failed to deserialize unit parameter '%s', ignoring.", l); } } } --- src/shared/time-util.c +++ src/shared/time-util.c 2015-06-17 00:00:00.000000000 +0000 @@ -375,18 +375,21 @@ void dual_timestamp_serialize(FILE *f, c (unsigned long long) t->monotonic); } -void dual_timestamp_deserialize(const char *value, dual_timestamp *t) { +int dual_timestamp_deserialize(const char *value, dual_timestamp *t) { unsigned long long a, b; assert(value); assert(t); - if (sscanf(value, "%llu %llu", &a, &b) != 2) - log_debug("Failed to parse finish timestamp value %s", value); - else { - t->realtime = a; - t->monotonic = b; + if (sscanf(value, "%llu %llu", &a, &b) != 2) { + log_debug("Failed to parse finish timestamp value %s.", value); + return -EINVAL; } + + t->realtime = a; + t->monotonic = b; + + return 0; } int parse_timestamp(const char *t, usec_t *usec) { --- src/shared/time-util.h +++ src/shared/time-util.h 2015-06-17 00:00:00.000000000 +0000 @@ -86,7 +86,7 @@ char *format_timestamp_relative(char *bu char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy); void dual_timestamp_serialize(FILE *f, const char *name, dual_timestamp *t); -void dual_timestamp_deserialize(const char *value, dual_timestamp *t); +int dual_timestamp_deserialize(const char *value, dual_timestamp *t); int parse_timestamp(const char *t, usec_t *usec);
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor