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/cryptsetup/cryptsetup.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/cryptsetup') diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c index a67d85e623..67dc88fa51 100644 --- a/src/cryptsetup/cryptsetup.c +++ b/src/cryptsetup/cryptsetup.c @@ -549,13 +549,18 @@ int main(int argc, char *argv[]) { description = NULL; } + k = 0; if (mount_point && description) - asprintf(&name_buffer, "%s (%s) on %s", description, argv[2], mount_point); + k = asprintf(&name_buffer, "%s (%s) on %s", description, argv[2], mount_point); else if (mount_point) - asprintf(&name_buffer, "%s on %s", argv[2], mount_point); + k = asprintf(&name_buffer, "%s on %s", argv[2], mount_point); else if (description) - asprintf(&name_buffer, "%s (%s)", description, argv[2]); + k = asprintf(&name_buffer, "%s (%s)", description, argv[2]); + if (k < 0) { + log_oom(); + goto finish; + } name = name_buffer ? name_buffer : argv[2]; k = crypt_init(&cd, argv[3]); -- cgit v1.2.3-54-g00ecf