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/core/unit-printf.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/core/unit-printf.c') diff --git a/src/core/unit-printf.c b/src/core/unit-printf.c index 5bd30f0bf7..62599d0813 100644 --- a/src/core/unit-printf.c +++ b/src/core/unit-printf.c @@ -182,7 +182,7 @@ static int specifier_user_name(char specifier, void *data, void *userdata, char char *printed = NULL; Unit *u = userdata; ExecContext *c; - int r; + int r = 0; assert(u); @@ -208,7 +208,7 @@ static int specifier_user_name(char specifier, void *data, void *userdata, char if (r < 0) return -ENODATA; - asprintf(&printed, UID_FMT, uid); + r = asprintf(&printed, UID_FMT, uid); } } @@ -231,10 +231,10 @@ static int specifier_user_name(char specifier, void *data, void *userdata, char if (specifier == 'u') printed = strdup(username); else - asprintf(&printed, UID_FMT, uid); + r = asprintf(&printed, UID_FMT, uid); } - if (!printed) + if (r < 0 || !printed) return -ENOMEM; *ret = printed; -- cgit v1.2.3-54-g00ecf