From 7de80bfe2e61d5818601ccfddbadad3b7703ed70 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Fri, 25 Jul 2014 15:38:31 +0200 Subject: 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. --- src/systemctl/systemctl.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src/systemctl') diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index fc325095ac..f3d7fc8d6e 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -4999,11 +4999,10 @@ static int enable_sysv_units(const char *verb, char **args) { _cleanup_free_ char *path = NULL; if (!isempty(arg_root)) - asprintf(&path, "%s/%s/%s", arg_root, *k, name); + j = asprintf(&path, "%s/%s/%s", arg_root, *k, name); else - asprintf(&path, "%s/%s", *k, name); - - if (!path) { + j = asprintf(&path, "%s/%s", *k, name); + if (j < 0) { r = log_oom(); goto finish; } @@ -5017,10 +5016,10 @@ static int enable_sysv_units(const char *verb, char **args) { continue; if (!isempty(arg_root)) - asprintf(&p, "%s/" SYSTEM_SYSVINIT_PATH "/%s", arg_root, name); + j = asprintf(&p, "%s/" SYSTEM_SYSVINIT_PATH "/%s", arg_root, name); else - asprintf(&p, SYSTEM_SYSVINIT_PATH "/%s", name); - if (!p) { + j = asprintf(&p, SYSTEM_SYSVINIT_PATH "/%s", name); + if (j < 0) { r = log_oom(); goto finish; } -- cgit v1.2.3-54-g00ecf