wutdevoptab: Prevent file-offset overflow in seek implementation

This commit is contained in:
Maschell 2022-07-30 00:45:26 +02:00 committed by fincs
parent 3469036c44
commit a902da1ce7

View File

@ -49,11 +49,14 @@ __wut_fs_seek(struct _reent *r,
return -1;
}
// TODO: A better check that prevents overflow.
if(pos < 0 && offset < -pos) {
// Don't allow seek to before the beginning of the file
r->_errno = EINVAL;
return -1;
} else if (offset + pos > UINT32_MAX) {
// Check for overflow
r->_errno = EINVAL;
return -1;
}
uint32_t old_offset = file->offset;