mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-17 05:40:13 +01:00
Annotate LGTM TOCTOU condition.
The race here is not avoidable.
This commit is contained in:
@@ -351,7 +351,7 @@ int device_open_excl(struct crypt_device *cd, struct device *device, int flags)
|
||||
else {
|
||||
/* open(2) with O_EXCL (w/o O_CREAT) on regular file is undefined behaviour according to man page */
|
||||
/* coverity[toctou] */
|
||||
device->dev_fd_excl = open(path, O_RDONLY | O_EXCL);
|
||||
device->dev_fd_excl = open(path, O_RDONLY | O_EXCL); /* lgtm[cpp/toctou-race-condition] */
|
||||
if (device->dev_fd_excl < 0)
|
||||
return errno == EBUSY ? -EBUSY : device->dev_fd_excl;
|
||||
if (fstat(device->dev_fd_excl, &st) || !S_ISBLK(st.st_mode)) {
|
||||
|
||||
@@ -229,7 +229,7 @@ static void release_lock_handle(struct crypt_device *cd, struct crypt_lock_handl
|
||||
!stat(res, &buf_b) && /* does path file still exist? */
|
||||
same_inode(buf_a, buf_b)) { /* is it same id as the one referenced by fd? */
|
||||
/* coverity[toctou] */
|
||||
if (unlink(res)) /* yes? unlink the file */
|
||||
if (unlink(res)) /* yes? unlink the file. lgtm[cpp/toctou-race-condition] */
|
||||
log_dbg(cd, "Failed to unlink resource file: %s", res);
|
||||
}
|
||||
|
||||
@@ -240,7 +240,7 @@ static void release_lock_handle(struct crypt_device *cd, struct crypt_lock_handl
|
||||
!stat(res, &buf_b) && /* does path file still exist? */
|
||||
same_inode(buf_a, buf_b)) { /* is it same id as the one referenced by fd? */
|
||||
/* coverity[toctou] */
|
||||
if (unlink(res)) /* yes? unlink the file */
|
||||
if (unlink(res)) /* yes? unlink the file. lgtm[cpp/toctou-race-condition] */
|
||||
log_dbg(cd, "Failed to unlink resource file: %s", res);
|
||||
}
|
||||
|
||||
|
||||
@@ -281,7 +281,7 @@ int tools_wipe_all_signatures(const char *path)
|
||||
|
||||
/* better than opening regular file with O_EXCL (undefined) */
|
||||
/* coverity[toctou] */
|
||||
fd = open(path, flags);
|
||||
fd = open(path, flags); /* lgtm[cpp/toctou-race-condition] */
|
||||
if (fd < 0) {
|
||||
if (errno == EBUSY)
|
||||
log_err(_("Device %s is in use. Cannot proceed with format operation."), path);
|
||||
|
||||
@@ -123,7 +123,7 @@ static int device_check(struct reenc_ctx *rc, const char *device, header_magic s
|
||||
}
|
||||
|
||||
/* coverity[toctou] */
|
||||
devfd = open(device, O_RDWR | ((S_ISBLK(st.st_mode) && exclusive) ? O_EXCL : 0));
|
||||
devfd = open(device, O_RDWR | ((S_ISBLK(st.st_mode) && exclusive) ? O_EXCL : 0)); /* lgtm[cpp/toctou-race-condition] */
|
||||
if (devfd == -1) {
|
||||
if (errno == EBUSY) {
|
||||
log_err(_("Cannot exclusively open %s, device in use."),
|
||||
|
||||
Reference in New Issue
Block a user