diff options
author | Karel Zak <kzak@redhat.com> | 2014-07-25 15:38:31 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2014-07-26 15:08:41 -0400 |
commit | 7de80bfe2e61d5818601ccfddbadad3b7703ed70 (patch) | |
tree | b8b90c03198f2f2125d13e175b2223e6239894f0 /src/shared | |
parent | 6d314eca15f6cbda38d82774b210f784d3d4f52a (diff) |
Always check asprintf return code
There is a small number of the places in sources where we don't check
asprintf() return code and assume that after error the function
returns NULL pointer via the first argument. That's wrong, after
error the content of pointer is undefined.
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/install.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/shared/install.c b/src/shared/install.c index a2f84f893e..e957c33344 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -88,13 +88,16 @@ static int get_config_path(UnitFileScope scope, bool runtime, const char *root_d case UNIT_FILE_SYSTEM: - if (root_dir && runtime) - asprintf(&p, "%s/run/systemd/system", root_dir); - else if (runtime) + if (root_dir && runtime) { + if (asprintf(&p, "%s/run/systemd/system", root_dir) < 0) + return -ENOMEM; + } else if (runtime) p = strdup("/run/systemd/system"); - else if (root_dir) - asprintf(&p, "%s/%s", root_dir, SYSTEM_CONFIG_UNIT_PATH); - else + else if (root_dir) { + if (asprintf(&p, "%s/%s", root_dir, + SYSTEM_CONFIG_UNIT_PATH) < 0) + return -ENOMEM; + } else p = strdup(SYSTEM_CONFIG_UNIT_PATH); break; |