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.
This commit is contained in:
Karel Zak
2014-07-26 15:08:41 -04:00
committed by Zbigniew Jędrzejewski-Szmek
parent 6d314eca15
commit 7de80bfe2e
8 changed files with 52 additions and 38 deletions
+8 -3
View File
@@ -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]);