Skip to content

Commit 8ab6e29

Browse files
cfriedtkartben
authored andcommitted
posix: shm: ensure addend is less than INTPTR_MAX
Although it's quite unlikely that we will see shared memory objects in practice that are greater than 2GiB, there is a possibility of integer overflow when comparing intptr_t and size_t, since the former is signed and the latter is unsigned. Explicitly check to ensure that the addend is less than INTPTR_MAX before subtraction. This fixes CID 487734 Signed-off-by: Chris Friedt <[email protected]>
1 parent f81293d commit 8ab6e29

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/posix/options/shm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ static off_t shm_lseek(struct shm_obj *shm, off_t offset, int whence, size_t cur
159159
return -1;
160160
}
161161

162-
if ((INTPTR_MAX - addend) < offset) {
162+
if ((addend > INTPTR_MAX) || ((INTPTR_MAX - addend) < offset)) {
163163
errno = EOVERFLOW;
164164
return -1;
165165
}

0 commit comments

Comments
 (0)