mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-14 20:30:04 +01:00
Check all snprintf calls for returning values for tests.
This commit is contained in:
@@ -382,8 +382,9 @@ static int _setup(void)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
snprintf(cmd, sizeof(cmd), "dd if=/dev/zero of=%s bs=%d count=%d 2>/dev/null",
|
if (snprintf(cmd, sizeof(cmd), "dd if=/dev/zero of=%s bs=%d count=%d 2>/dev/null",
|
||||||
test_loop_file, TST_SECTOR_SIZE, TST_LOOP_FILE_SIZE);
|
test_loop_file, TST_SECTOR_SIZE, TST_LOOP_FILE_SIZE) < 0)
|
||||||
|
return 1;
|
||||||
if (_system(cmd, 1))
|
if (_system(cmd, 1))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
@@ -399,8 +400,9 @@ static int _setup(void)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
snprintf(cmd, sizeof(cmd), "dd if=/dev/zero of=%s bs=%d count=%d 2>/dev/null",
|
if (snprintf(cmd, sizeof(cmd), "dd if=/dev/zero of=%s bs=%d count=%d 2>/dev/null",
|
||||||
tmp_file_1, TST_SECTOR_SIZE, 10);
|
tmp_file_1, TST_SECTOR_SIZE, 10) < 0)
|
||||||
|
return 1;
|
||||||
if (_system(cmd, 1))
|
if (_system(cmd, 1))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
@@ -1189,9 +1191,9 @@ static void UseTempVolumes(void)
|
|||||||
|
|
||||||
// Dirty checks: device without UUID
|
// Dirty checks: device without UUID
|
||||||
// we should be able to remove it but not manipulate with it
|
// we should be able to remove it but not manipulate with it
|
||||||
snprintf(tmp, sizeof(tmp), "dmsetup create %s --table \""
|
GE_(snprintf(tmp, sizeof(tmp), "dmsetup create %s --table \""
|
||||||
"0 100 crypt aes-cbc-essiv:sha256 deadbabedeadbabedeadbabedeadbabe 0 "
|
"0 100 crypt aes-cbc-essiv:sha256 deadbabedeadbabedeadbabedeadbabe 0 "
|
||||||
"%s 2048\"", CDEVICE_2, DEVICE_2);
|
"%s 2048\"", CDEVICE_2, DEVICE_2), 0);
|
||||||
_system(tmp, 1);
|
_system(tmp, 1);
|
||||||
OK_(crypt_init_by_name(&cd, CDEVICE_2));
|
OK_(crypt_init_by_name(&cd, CDEVICE_2));
|
||||||
OK_(crypt_deactivate(cd, CDEVICE_2));
|
OK_(crypt_deactivate(cd, CDEVICE_2));
|
||||||
@@ -1199,10 +1201,10 @@ static void UseTempVolumes(void)
|
|||||||
CRYPT_FREE(cd);
|
CRYPT_FREE(cd);
|
||||||
|
|
||||||
// Dirty checks: device with UUID but LUKS header key fingerprint must fail)
|
// Dirty checks: device with UUID but LUKS header key fingerprint must fail)
|
||||||
snprintf(tmp, sizeof(tmp), "dmsetup create %s --table \""
|
GE_(snprintf(tmp, sizeof(tmp), "dmsetup create %s --table \""
|
||||||
"0 100 crypt aes-cbc-essiv:sha256 deadbabedeadbabedeadbabedeadbabe 0 "
|
"0 100 crypt aes-cbc-essiv:sha256 deadbabedeadbabedeadbabedeadbabe 0 "
|
||||||
"%s 2048\" -u CRYPT-LUKS2-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-ctest1",
|
"%s 2048\" -u CRYPT-LUKS2-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-ctest1",
|
||||||
CDEVICE_2, DEVICE_2);
|
CDEVICE_2, DEVICE_2), 0);
|
||||||
_system(tmp, 1);
|
_system(tmp, 1);
|
||||||
OK_(crypt_init_by_name(&cd, CDEVICE_2));
|
OK_(crypt_init_by_name(&cd, CDEVICE_2));
|
||||||
OK_(crypt_deactivate(cd, CDEVICE_2));
|
OK_(crypt_deactivate(cd, CDEVICE_2));
|
||||||
@@ -1368,7 +1370,8 @@ static void Luks2HeaderLoad(void)
|
|||||||
// prepared header on a device too small to contain header and payload
|
// prepared header on a device too small to contain header and payload
|
||||||
//OK_(create_dmdevice_over_loop(H_DEVICE_WRONG, r_payload_offset - 1));
|
//OK_(create_dmdevice_over_loop(H_DEVICE_WRONG, r_payload_offset - 1));
|
||||||
OK_(create_dmdevice_over_loop(H_DEVICE_WRONG, img_size - 1));
|
OK_(create_dmdevice_over_loop(H_DEVICE_WRONG, img_size - 1));
|
||||||
snprintf(cmd, sizeof(cmd), "dd if=" IMAGE1 " of=" DMDIR H_DEVICE_WRONG " bs=%" PRIu32 " count=%" PRIu64 " 2>/dev/null", params.sector_size, img_size - 1);
|
GE_(snprintf(cmd, sizeof(cmd), "dd if=" IMAGE1 " of=" DMDIR H_DEVICE_WRONG " bs=%" PRIu32
|
||||||
|
" count=%" PRIu64 " 2>/dev/null", params.sector_size, img_size - 1), 0);
|
||||||
OK_(_system(cmd, 1));
|
OK_(_system(cmd, 1));
|
||||||
// some device
|
// some device
|
||||||
OK_(create_dmdevice_over_loop(L_DEVICE_OK, r_payload_offset + 1000));
|
OK_(create_dmdevice_over_loop(L_DEVICE_OK, r_payload_offset + 1000));
|
||||||
@@ -4569,9 +4572,8 @@ static void Luks2Repair(void)
|
|||||||
{
|
{
|
||||||
char rollback[256];
|
char rollback[256];
|
||||||
|
|
||||||
snprintf(rollback, sizeof(rollback),
|
GE_(snprintf(rollback, sizeof(rollback),
|
||||||
"dd if=" IMAGE_PV_LUKS2_SEC ".bcp of=%s bs=1M 2>/dev/null",
|
"dd if=" IMAGE_PV_LUKS2_SEC ".bcp of=%s bs=1M 2>/dev/null", DEVICE_6), 0);
|
||||||
DEVICE_6);
|
|
||||||
|
|
||||||
OK_(crypt_init(&cd, DEVICE_6));
|
OK_(crypt_init(&cd, DEVICE_6));
|
||||||
|
|
||||||
|
|||||||
@@ -245,8 +245,9 @@ static int _setup(void)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
snprintf(cmd, sizeof(cmd), "dd if=/dev/zero of=%s bs=%d count=%d 2>/dev/null",
|
if (snprintf(cmd, sizeof(cmd), "dd if=/dev/zero of=%s bs=%d count=%d 2>/dev/null",
|
||||||
test_loop_file, TST_SECTOR_SIZE, TST_LOOP_FILE_SIZE);
|
test_loop_file, TST_SECTOR_SIZE, TST_LOOP_FILE_SIZE) < 0)
|
||||||
|
return 1;
|
||||||
if (_system(cmd, 1))
|
if (_system(cmd, 1))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
@@ -262,8 +263,9 @@ static int _setup(void)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
snprintf(cmd, sizeof(cmd), "dd if=/dev/zero of=%s bs=%d count=%d 2>/dev/null",
|
if (snprintf(cmd, sizeof(cmd), "dd if=/dev/zero of=%s bs=%d count=%d 2>/dev/null",
|
||||||
tmp_file_1, TST_SECTOR_SIZE, 10);
|
tmp_file_1, TST_SECTOR_SIZE, 10) < 0)
|
||||||
|
return 1;
|
||||||
if (_system(cmd, 1))
|
if (_system(cmd, 1))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
@@ -384,7 +386,7 @@ static void AddDevicePlain(void)
|
|||||||
OK_(crypt_format(cd, CRYPT_PLAIN, cipher, cipher_mode, NULL, NULL, key_size, ¶ms));
|
OK_(crypt_format(cd, CRYPT_PLAIN, cipher, cipher_mode, NULL, NULL, key_size, ¶ms));
|
||||||
OK_(crypt_activate_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, passphrase, strlen(passphrase), 0));
|
OK_(crypt_activate_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, passphrase, strlen(passphrase), 0));
|
||||||
GE_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
|
GE_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
|
||||||
snprintf(path, sizeof(path), "%s/%s", crypt_get_dir(), CDEVICE_1);
|
GE_(snprintf(path, sizeof(path), "%s/%s", crypt_get_dir(), CDEVICE_1), 0);
|
||||||
if (t_device_size(path, &r_size) >= 0)
|
if (t_device_size(path, &r_size) >= 0)
|
||||||
EQ_(r_size >> TST_SECTOR_SHIFT, 1);
|
EQ_(r_size >> TST_SECTOR_SHIFT, 1);
|
||||||
OK_(crypt_deactivate(cd, CDEVICE_1));
|
OK_(crypt_deactivate(cd, CDEVICE_1));
|
||||||
@@ -452,7 +454,7 @@ static void AddDevicePlain(void)
|
|||||||
|
|
||||||
// device status check
|
// device status check
|
||||||
GE_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
|
GE_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
|
||||||
snprintf(path, sizeof(path), "%s/%s", crypt_get_dir(), CDEVICE_1);
|
GE_(snprintf(path, sizeof(path), "%s/%s", crypt_get_dir(), CDEVICE_1), 0);
|
||||||
fd = open(path, O_RDONLY);
|
fd = open(path, O_RDONLY);
|
||||||
EQ_(crypt_status(cd, CDEVICE_1), CRYPT_BUSY);
|
EQ_(crypt_status(cd, CDEVICE_1), CRYPT_BUSY);
|
||||||
FAIL_(crypt_deactivate(cd, CDEVICE_1), "Device is busy");
|
FAIL_(crypt_deactivate(cd, CDEVICE_1), "Device is busy");
|
||||||
@@ -1078,9 +1080,9 @@ static void UseTempVolumes(void)
|
|||||||
|
|
||||||
// Dirty checks: device without UUID
|
// Dirty checks: device without UUID
|
||||||
// we should be able to remove it but not manipulate with it
|
// we should be able to remove it but not manipulate with it
|
||||||
snprintf(tmp, sizeof(tmp), "dmsetup create %s --table \""
|
GE_(snprintf(tmp, sizeof(tmp), "dmsetup create %s --table \""
|
||||||
"0 100 crypt aes-cbc-essiv:sha256 deadbabedeadbabedeadbabedeadbabe 0 "
|
"0 100 crypt aes-cbc-essiv:sha256 deadbabedeadbabedeadbabedeadbabe 0 "
|
||||||
"%s 2048\"", CDEVICE_2, DEVICE_2);
|
"%s 2048\"", CDEVICE_2, DEVICE_2), 0);
|
||||||
_system(tmp, 1);
|
_system(tmp, 1);
|
||||||
OK_(crypt_init_by_name(&cd, CDEVICE_2));
|
OK_(crypt_init_by_name(&cd, CDEVICE_2));
|
||||||
OK_(crypt_deactivate(cd, CDEVICE_2));
|
OK_(crypt_deactivate(cd, CDEVICE_2));
|
||||||
@@ -1088,10 +1090,10 @@ static void UseTempVolumes(void)
|
|||||||
CRYPT_FREE(cd);
|
CRYPT_FREE(cd);
|
||||||
|
|
||||||
// Dirty checks: device with UUID but LUKS header key fingerprint must fail)
|
// Dirty checks: device with UUID but LUKS header key fingerprint must fail)
|
||||||
snprintf(tmp, sizeof(tmp), "dmsetup create %s --table \""
|
GE_(snprintf(tmp, sizeof(tmp), "dmsetup create %s --table \""
|
||||||
"0 100 crypt aes-cbc-essiv:sha256 deadbabedeadbabedeadbabedeadbabe 0 "
|
"0 100 crypt aes-cbc-essiv:sha256 deadbabedeadbabedeadbabedeadbabe 0 "
|
||||||
"%s 2048\" -u CRYPT-LUKS1-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-ctest1",
|
"%s 2048\" -u CRYPT-LUKS1-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-ctest1",
|
||||||
CDEVICE_2, DEVICE_2);
|
CDEVICE_2, DEVICE_2), 0);
|
||||||
_system(tmp, 1);
|
_system(tmp, 1);
|
||||||
OK_(crypt_init_by_name(&cd, CDEVICE_2));
|
OK_(crypt_init_by_name(&cd, CDEVICE_2));
|
||||||
OK_(crypt_deactivate(cd, CDEVICE_2));
|
OK_(crypt_deactivate(cd, CDEVICE_2));
|
||||||
@@ -1161,7 +1163,7 @@ static void LuksHeaderRestore(void)
|
|||||||
FAIL_(crypt_header_restore(cd, CRYPT_LUKS1, EVL_HEADER_5), "Header corrupted");
|
FAIL_(crypt_header_restore(cd, CRYPT_LUKS1, EVL_HEADER_5), "Header corrupted");
|
||||||
OK_(crypt_header_restore(cd, CRYPT_LUKS1, VALID_HEADER));
|
OK_(crypt_header_restore(cd, CRYPT_LUKS1, VALID_HEADER));
|
||||||
// wipe valid luks header
|
// wipe valid luks header
|
||||||
snprintf(cmd, sizeof(cmd), "dd if=/dev/zero of=" DMDIR L_DEVICE_OK " bs=512 count=%" PRIu64 " 2>/dev/null", r_payload_offset);
|
GE_(snprintf(cmd, sizeof(cmd), "dd if=/dev/zero of=" DMDIR L_DEVICE_OK " bs=512 count=%" PRIu64 " 2>/dev/null", r_payload_offset), 0);
|
||||||
OK_(_system(cmd, 1));
|
OK_(_system(cmd, 1));
|
||||||
FAIL_(crypt_header_restore(cd, CRYPT_LUKS1, EVL_HEADER_1), "Header corrupted");
|
FAIL_(crypt_header_restore(cd, CRYPT_LUKS1, EVL_HEADER_1), "Header corrupted");
|
||||||
FAIL_(crypt_header_restore(cd, CRYPT_LUKS1, EVL_HEADER_2), "Header corrupted");
|
FAIL_(crypt_header_restore(cd, CRYPT_LUKS1, EVL_HEADER_2), "Header corrupted");
|
||||||
@@ -1233,8 +1235,8 @@ static void LuksHeaderLoad(void)
|
|||||||
// prepared header on a device too small to contain header and payload
|
// prepared header on a device too small to contain header and payload
|
||||||
//OK_(create_dmdevice_over_loop(H_DEVICE_WRONG, r_payload_offset - 1));
|
//OK_(create_dmdevice_over_loop(H_DEVICE_WRONG, r_payload_offset - 1));
|
||||||
OK_(create_dmdevice_over_loop(H_DEVICE_WRONG, 2050 - 1)); //FIXME
|
OK_(create_dmdevice_over_loop(H_DEVICE_WRONG, 2050 - 1)); //FIXME
|
||||||
//snprintf(cmd, sizeof(cmd), "dd if=" EVL_HEADER_4 " of=" DMDIR H_DEVICE_WRONG " bs=512 count=%" PRIu64, r_payload_offset - 1);
|
//GE_(snprintf(cmd, sizeof(cmd), "dd if=" EVL_HEADER_4 " of=" DMDIR H_DEVICE_WRONG " bs=512 count=%" PRIu64, r_payload_offset - 1), 0);
|
||||||
snprintf(cmd, sizeof(cmd), "dd if=" EVL_HEADER_4 " of=" DMDIR H_DEVICE_WRONG " bs=512 count=%d 2>/dev/null", 2050 - 1);
|
GE_(snprintf(cmd, sizeof(cmd), "dd if=" EVL_HEADER_4 " of=" DMDIR H_DEVICE_WRONG " bs=512 count=%d 2>/dev/null", 2050 - 1), 0);
|
||||||
OK_(_system(cmd, 1));
|
OK_(_system(cmd, 1));
|
||||||
// some device
|
// some device
|
||||||
OK_(create_dmdevice_over_loop(L_DEVICE_OK, r_payload_offset + 1000));
|
OK_(create_dmdevice_over_loop(L_DEVICE_OK, r_payload_offset + 1000));
|
||||||
|
|||||||
@@ -1303,7 +1303,9 @@ static int cipher_iv_test(void)
|
|||||||
if (vector->data_length > sizeof(result))
|
if (vector->data_length > sizeof(result))
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
snprintf(mode_iv, sizeof(mode_iv)-2, "%s-%s", vector->cipher_mode, vector->iv_name);
|
if (snprintf(mode_iv, sizeof(mode_iv)-2, "%s-%s", vector->cipher_mode, vector->iv_name) < 0)
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
r = crypt_storage_init(&storage, vector->out[j].sector_size, vector->cipher_name, mode_iv,
|
r = crypt_storage_init(&storage, vector->out[j].sector_size, vector->cipher_name, mode_iv,
|
||||||
vector->key, vector->key_length, vector->out[j].large_iv);
|
vector->key, vector->key_length, vector->out[j].large_iv);
|
||||||
if (r == -ENOENT || r == -ENOTSUP) {
|
if (r == -ENOENT || r == -ENOTSUP) {
|
||||||
|
|||||||
@@ -196,9 +196,12 @@ int create_dmdevice_over_loop(const char *dm_name, const uint64_t size)
|
|||||||
printf("No enough space on backing loop device\n.");
|
printf("No enough space on backing loop device\n.");
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
snprintf(cmd, sizeof(cmd),
|
r = snprintf(cmd, sizeof(cmd),
|
||||||
"dmsetup create %s --table \"0 %" PRIu64 " linear %s %" PRIu64 "\"",
|
"dmsetup create %s --table \"0 %" PRIu64 " linear %s %" PRIu64 "\"",
|
||||||
dm_name, size, THE_LOOP_DEV, t_dev_offset);
|
dm_name, size, THE_LOOP_DEV, t_dev_offset);
|
||||||
|
if (r < 0 || (size_t)r >= sizeof(cmd))
|
||||||
|
return -3;
|
||||||
|
|
||||||
if (!(r = _system(cmd, 1)))
|
if (!(r = _system(cmd, 1)))
|
||||||
t_dev_offset += size;
|
t_dev_offset += size;
|
||||||
return r;
|
return r;
|
||||||
|
|||||||
Reference in New Issue
Block a user