mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-11 10:50:01 +01:00
Check all snprintf calls for returning values.
This commit is contained in:
@@ -1740,7 +1740,8 @@ static void hdr_dump_keyslots(struct crypt_device *cd, json_object *hdr_jobj)
|
||||
json_object_object_get_ex(hdr_jobj, "keyslots", &keyslots_jobj);
|
||||
|
||||
for (j = 0; j < LUKS2_KEYSLOTS_MAX; j++) {
|
||||
(void) snprintf(slot, sizeof(slot), "%i", j);
|
||||
if (snprintf(slot, sizeof(slot), "%i", j) < 0)
|
||||
slot[0] = '\0';
|
||||
json_object_object_get_ex(keyslots_jobj, slot, &val);
|
||||
if (!val)
|
||||
continue;
|
||||
@@ -1782,7 +1783,8 @@ static void hdr_dump_tokens(struct crypt_device *cd, json_object *hdr_jobj)
|
||||
json_object_object_get_ex(hdr_jobj, "tokens", &tokens_jobj);
|
||||
|
||||
for (j = 0; j < LUKS2_TOKENS_MAX; j++) {
|
||||
(void) snprintf(token, sizeof(token), "%i", j);
|
||||
if (snprintf(token, sizeof(token), "%i", j) < 0)
|
||||
token[0] = '\0';
|
||||
json_object_object_get_ex(tokens_jobj, token, &val);
|
||||
if (!val)
|
||||
continue;
|
||||
@@ -1812,7 +1814,8 @@ static void hdr_dump_segments(struct crypt_device *cd, json_object *hdr_jobj)
|
||||
json_object_object_get_ex(hdr_jobj, "segments", &jobj_segments);
|
||||
|
||||
for (i = 0; i < LUKS2_SEGMENT_MAX; i++) {
|
||||
(void) snprintf(segment, sizeof(segment), "%i", i);
|
||||
if (snprintf(segment, sizeof(segment), "%i", i) < 0)
|
||||
segment[0] = '\0';
|
||||
if (!json_object_object_get_ex(jobj_segments, segment, &jobj_segment))
|
||||
continue;
|
||||
|
||||
@@ -1867,7 +1870,8 @@ static void hdr_dump_digests(struct crypt_device *cd, json_object *hdr_jobj)
|
||||
json_object_object_get_ex(hdr_jobj, "digests", &jobj1);
|
||||
|
||||
for (i = 0; i < LUKS2_DIGEST_MAX; i++) {
|
||||
(void) snprintf(key, sizeof(key), "%i", i);
|
||||
if (snprintf(key, sizeof(key), "%i", i) < 0)
|
||||
key[0] = '\0';
|
||||
json_object_object_get_ex(jobj1, key, &val);
|
||||
if (!val)
|
||||
continue;
|
||||
|
||||
@@ -75,7 +75,11 @@ static int json_luks1_keyslot(const struct luks_phdr *hdr_v1, int keyslot, struc
|
||||
|
||||
/* encryption algorithm field */
|
||||
if (*hdr_v1->cipherMode != '\0') {
|
||||
(void) snprintf(cipher, sizeof(cipher), "%s-%s", hdr_v1->cipherName, hdr_v1->cipherMode);
|
||||
if (snprintf(cipher, sizeof(cipher), "%s-%s", hdr_v1->cipherName, hdr_v1->cipherMode) < 0) {
|
||||
json_object_put(keyslot_obj);
|
||||
json_object_put(jobj_area);
|
||||
return -EINVAL;
|
||||
}
|
||||
json_object_object_add(jobj_area, "encryption", json_object_new_string(cipher));
|
||||
} else
|
||||
json_object_object_add(jobj_area, "encryption", json_object_new_string(hdr_v1->cipherName));
|
||||
@@ -169,7 +173,10 @@ static int json_luks1_segment(const struct luks_phdr *hdr_v1, struct json_object
|
||||
|
||||
/* cipher field */
|
||||
if (*hdr_v1->cipherMode != '\0') {
|
||||
(void) snprintf(cipher, sizeof(cipher), "%s-%s", hdr_v1->cipherName, hdr_v1->cipherMode);
|
||||
if (snprintf(cipher, sizeof(cipher), "%s-%s", hdr_v1->cipherName, hdr_v1->cipherMode) < 0) {
|
||||
json_object_put(segment_obj);
|
||||
return -EINVAL;
|
||||
}
|
||||
c = cipher;
|
||||
} else
|
||||
c = hdr_v1->cipherName;
|
||||
@@ -243,7 +250,12 @@ static int json_luks1_digest(const struct luks_phdr *hdr_v1, struct json_object
|
||||
for (ks = 0; ks < LUKS_NUMKEYS; ks++) {
|
||||
if (hdr_v1->keyblock[ks].active != LUKS_KEY_ENABLED)
|
||||
continue;
|
||||
(void) snprintf(keyslot_str, sizeof(keyslot_str), "%d", ks);
|
||||
if (snprintf(keyslot_str, sizeof(keyslot_str), "%d", ks) < 0) {
|
||||
json_object_put(field);
|
||||
json_object_put(array);
|
||||
json_object_put(digest_obj);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
field = json_object_new_string(keyslot_str);
|
||||
if (!field || json_object_array_add(array, field) < 0) {
|
||||
|
||||
Reference in New Issue
Block a user