From: Zbigniew Jędrzejewski-Szmek Date: Thu, 1 Aug 2019 06:15:43 +0000 (+0200) Subject: cryptsetup: don't assert on variable which is optional X-Git-Tag: v243-rc2~70^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F13243%2Fhead;p=thirdparty%2Fsystemd.git cryptsetup: don't assert on variable which is optional https://github.com/systemd/systemd/commit/50d2eba27b9bfc77ef6b40e5721713846815418b#commitcomment-34519739 In add_crypttab_devices() split_keyspec is called on the keyfile argument, which may be NULL. --- diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c index 84483143945..4815ded753f 100644 --- a/src/cryptsetup/cryptsetup-generator.c +++ b/src/cryptsetup/cryptsetup-generator.c @@ -50,10 +50,14 @@ static int split_keyspec(const char *keyspec, char **ret_keyfile, char **ret_key _cleanup_free_ char *keyfile = NULL, *keydev = NULL; const char *c; - assert(keyspec); assert(ret_keyfile); assert(ret_keydev); + if (!keyspec) { + *ret_keyfile = *ret_keydev = NULL; + return 0; + } + c = strrchr(keyspec, ':'); if (c) { keyfile = strndup(keyspec, c-keyspec); @@ -567,7 +571,7 @@ static int add_crypttab_devices(void) { } for (;;) { - _cleanup_free_ char *line = NULL, *name = NULL, *device = NULL, *keydev = NULL, *keyfile = NULL, *keyspec = NULL, *options = NULL; + _cleanup_free_ char *line = NULL, *name = NULL, *device = NULL, *keyspec = NULL, *options = NULL, *keyfile = NULL, *keydev = NULL; crypto_device *d = NULL; char *l, *uuid; int k;