diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2019-02-16 22:35:46 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2019-02-16 23:31:07 +0100 |
commit | ea53cfd195f037a65b68a9749e310ab70e254805 (patch) | |
tree | 1fca48857d87de81c46aea5af069d2a102d8e47e /src/shared/calendarspec.c | |
parent | 7321d504e61eb14cb951a0e493d327130499f9d3 (diff) | |
download | systemd-ea53cfd195f037a65b68a9749e310ab70e254805.tar.gz |
shared/calendarspec: do not allocate a big string on stack
The string can be as long as a logical line in a unit file — so no unlimited,
but quite big. Let's use a normal heap allocation when making a copy.
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=13125
Diffstat (limited to 'src/shared/calendarspec.c')
-rw-r--r-- | src/shared/calendarspec.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/shared/calendarspec.c b/src/shared/calendarspec.c index dafc09e8f8..b2285cebdc 100644 --- a/src/shared/calendarspec.c +++ b/src/shared/calendarspec.c @@ -880,6 +880,7 @@ fail: int calendar_spec_from_string(const char *p, CalendarSpec **spec) { const char *utc; _cleanup_(calendar_spec_freep) CalendarSpec *c = NULL; + _cleanup_free_ char *p_tmp = NULL; int r; assert(p); @@ -894,7 +895,9 @@ int calendar_spec_from_string(const char *p, CalendarSpec **spec) { utc = endswith_no_case(p, " UTC"); if (utc) { c->utc = true; - p = strndupa(p, utc - p); + p = p_tmp = strndup(p, utc - p); + if (!p) + return -ENOMEM; } else { const char *e = NULL; int j; @@ -919,7 +922,10 @@ int calendar_spec_from_string(const char *p, CalendarSpec **spec) { /* Found one of the two timezones specified? */ if (IN_SET(j, 0, 1)) { - p = strndupa(p, e - p - 1); + p = p_tmp = strndup(p, e - p - 1); + if (!p) + return -ENOMEM; + c->dst = j; } else { const char *last_space; @@ -930,7 +936,9 @@ int calendar_spec_from_string(const char *p, CalendarSpec **spec) { if (!c->timezone) return -ENOMEM; - p = strndupa(p, last_space - p); + p = p_tmp = strndup(p, last_space - p); + if (!p) + return -ENOMEM; } } } |