mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-13 20:00:08 +01:00
Fix several issues found by Coverity scan.
This commit is contained in:
@@ -246,7 +246,7 @@ int crypt_storage_decrypt(struct crypt_storage *ctx,
|
|||||||
uint64_t iv_offset,
|
uint64_t iv_offset,
|
||||||
uint64_t length, char *buffer)
|
uint64_t length, char *buffer)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
uint64_t i;
|
||||||
int r = 0;
|
int r = 0;
|
||||||
|
|
||||||
if (length & ((1 << ctx->sector_shift) - 1))
|
if (length & ((1 << ctx->sector_shift) - 1))
|
||||||
@@ -275,7 +275,7 @@ int crypt_storage_encrypt(struct crypt_storage *ctx,
|
|||||||
uint64_t iv_offset,
|
uint64_t iv_offset,
|
||||||
uint64_t length, char *buffer)
|
uint64_t length, char *buffer)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
uint64_t i;
|
||||||
int r = 0;
|
int r = 0;
|
||||||
|
|
||||||
if (length & ((1 << ctx->sector_shift) - 1))
|
if (length & ((1 << ctx->sector_shift) - 1))
|
||||||
|
|||||||
@@ -301,12 +301,12 @@ static unsigned device_lock_dec(struct crypt_lock_handle *h)
|
|||||||
static int acquire_and_verify(struct crypt_device *cd, struct device *device, const char *resource, int flock_op, struct crypt_lock_handle **lock)
|
static int acquire_and_verify(struct crypt_device *cd, struct device *device, const char *resource, int flock_op, struct crypt_lock_handle **lock)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
struct crypt_lock_handle *h = malloc(sizeof(*h));
|
struct crypt_lock_handle *h;
|
||||||
|
|
||||||
if (device && resource)
|
if (device && resource)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if (!h)
|
if (!(h = malloc(sizeof(*h))))
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
@@ -329,7 +329,8 @@ static int acquire_and_verify(struct crypt_device *cd, struct device *device, co
|
|||||||
*/
|
*/
|
||||||
r = verify_lock_handle(device_path(device), h);
|
r = verify_lock_handle(device_path(device), h);
|
||||||
if (r) {
|
if (r) {
|
||||||
flock(h->flock_fd, LOCK_UN);
|
if (flock(h->flock_fd, LOCK_UN))
|
||||||
|
log_dbg(cd, "flock on fd %d failed.", h->flock_fd);
|
||||||
release_lock_handle(cd, h);
|
release_lock_handle(cd, h);
|
||||||
log_dbg(cd, "Lock handle verification failed.");
|
log_dbg(cd, "Lock handle verification failed.");
|
||||||
}
|
}
|
||||||
@@ -337,7 +338,7 @@ static int acquire_and_verify(struct crypt_device *cd, struct device *device, co
|
|||||||
|
|
||||||
if (r) {
|
if (r) {
|
||||||
free(h);
|
free(h);
|
||||||
return r;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
*lock = h;
|
*lock = h;
|
||||||
|
|||||||
@@ -185,6 +185,7 @@ int crypt_storage_wrapper_init(struct crypt_device *cd,
|
|||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
memset(w, 0, sizeof(*w));
|
memset(w, 0, sizeof(*w));
|
||||||
|
w->dev_fd = -1;
|
||||||
w->data_offset = data_offset;
|
w->data_offset = data_offset;
|
||||||
w->mem_alignment = device_alignment(device);
|
w->mem_alignment = device_alignment(device);
|
||||||
w->block_size = device_block_size(cd, device);
|
w->block_size = device_block_size(cd, device);
|
||||||
@@ -376,7 +377,8 @@ void crypt_storage_wrapper_destroy(struct crypt_storage_wrapper *cw)
|
|||||||
dm_remove_device(NULL, cw->u.dm.name, CRYPT_DEACTIVATE_FORCE);
|
dm_remove_device(NULL, cw->u.dm.name, CRYPT_DEACTIVATE_FORCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
close(cw->dev_fd);
|
if (cw->dev_fd >= 0)
|
||||||
|
close(cw->dev_fd);
|
||||||
|
|
||||||
free(cw);
|
free(cw);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user