mirror of
https://github.com/isar/libmdbx.git
synced 2025-03-01 16:18:15 +08:00
mdbx: add paranoid assertions for off_t
args of fcntl()
.
This commit is contained in:
parent
bb8f431817
commit
4628ac6863
@ -175,14 +175,28 @@ __cold static void choice_fcntl() {
|
|||||||
|
|
||||||
#ifndef OFF_T_MAX
|
#ifndef OFF_T_MAX
|
||||||
#define OFF_T_MAX \
|
#define OFF_T_MAX \
|
||||||
((sizeof(off_t) > 4 ? INT64_MAX : INT32_MAX) & ~(size_t)0xffff)
|
(((sizeof(off_t) > 4) ? INT64_MAX : INT32_MAX) & ~(size_t)0xffff)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int lck_op(mdbx_filehandle_t fd, int cmd, int lck, off_t offset,
|
static int lck_op(const mdbx_filehandle_t fd, int cmd, const int lck,
|
||||||
off_t len) {
|
const off_t offset, off_t len) {
|
||||||
mdbx_jitter4testing(true);
|
mdbx_jitter4testing(true);
|
||||||
|
assert(offset >= 0 && len > 0);
|
||||||
|
assert((uint64_t)offset < (uint64_t)INT64_MAX &&
|
||||||
|
(uint64_t)len < (uint64_t)INT64_MAX &&
|
||||||
|
(uint64_t)(offset + len) > (uint64_t)offset);
|
||||||
|
|
||||||
|
assert((uint64_t)offset < (uint64_t)OFF_T_MAX &&
|
||||||
|
(uint64_t)len <= (uint64_t)OFF_T_MAX &&
|
||||||
|
(uint64_t)(offset + len) <= (uint64_t)OFF_T_MAX);
|
||||||
|
|
||||||
|
assert((uint64_t)((off_t)((uint64_t)offset + (uint64_t)len)) ==
|
||||||
|
((uint64_t)offset + (uint64_t)len));
|
||||||
for (;;) {
|
for (;;) {
|
||||||
struct flock lock_op;
|
struct flock lock_op;
|
||||||
|
STATIC_ASSERT(sizeof(off_t) <= sizeof(lock_op.l_start) &&
|
||||||
|
sizeof(off_t) <= sizeof(lock_op.l_len) &&
|
||||||
|
OFF_T_MAX == (off_t)OFF_T_MAX);
|
||||||
memset(&lock_op, 0, sizeof(lock_op));
|
memset(&lock_op, 0, sizeof(lock_op));
|
||||||
lock_op.l_type = lck;
|
lock_op.l_type = lck;
|
||||||
lock_op.l_whence = SEEK_SET;
|
lock_op.l_whence = SEEK_SET;
|
||||||
@ -218,7 +232,7 @@ static int lck_op(mdbx_filehandle_t fd, int cmd, int lck, off_t offset,
|
|||||||
}
|
}
|
||||||
#endif /* MDBX_USE_OFDLOCKS */
|
#endif /* MDBX_USE_OFDLOCKS */
|
||||||
if (rc != EINTR || cmd == op_setlkw) {
|
if (rc != EINTR || cmd == op_setlkw) {
|
||||||
mdbx_assert(nullptr, MDBX_IS_ERROR(rc));
|
assert(MDBX_IS_ERROR(rc));
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user