summaryrefslogtreecommitdiffstats
path: root/lib/luks2/luks2_digest_pbkdf2.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/luks2/luks2_digest_pbkdf2.c')
-rw-r--r--lib/luks2/luks2_digest_pbkdf2.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/luks2/luks2_digest_pbkdf2.c b/lib/luks2/luks2_digest_pbkdf2.c
index 1009cfb..e8fd00d 100644
--- a/lib/luks2/luks2_digest_pbkdf2.c
+++ b/lib/luks2/luks2_digest_pbkdf2.c
@@ -1,8 +1,8 @@
/*
* LUKS - Linux Unified Key Setup v2, PBKDF2 digest handler (LUKS1 compatible)
*
- * Copyright (C) 2015-2023 Red Hat, Inc. All rights reserved.
- * Copyright (C) 2015-2023 Milan Broz
+ * Copyright (C) 2015-2024 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2015-2024 Milan Broz
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -147,6 +147,9 @@ static int PBKDF2_digest_store(struct crypt_device *cd,
json_object_object_get_ex(hdr->jobj, "digests", &jobj_digests);
}
+ if (!jobj_digest)
+ return -ENOMEM;
+
json_object_object_add(jobj_digest, "type", json_object_new_string("pbkdf2"));
json_object_object_add(jobj_digest, "keyslots", json_object_new_array());
json_object_object_add(jobj_digest, "segments", json_object_new_array());
@@ -169,8 +172,13 @@ static int PBKDF2_digest_store(struct crypt_device *cd,
json_object_object_add(jobj_digest, "digest", json_object_new_string(base64_str));
free(base64_str);
- if (jobj_digests)
- json_object_object_add_by_uint(jobj_digests, digest, jobj_digest);
+ if (jobj_digests) {
+ r = json_object_object_add_by_uint(jobj_digests, digest, jobj_digest);
+ if (r < 0) {
+ json_object_put(jobj_digest);
+ return r;
+ }
+ }
JSON_DBG(cd, jobj_digest, "Digest JSON:");
return 0;