diff options
author | Christopher Haster <chaster@utexas.edu> | 2018-01-04 00:00:04 +0300 |
---|---|---|
committer | Christopher Haster <chaster@utexas.edu> | 2018-01-04 00:00:04 +0300 |
commit | aea3d3db46634bf26298c8df0be020c03b80daba (patch) | |
tree | 419e29313c61583acb494ae125b8fdf6290f73cd /lfs.c | |
parent | be22d3449f23a24e7462114349ce04d751e42437 (diff) |
Fixed positive seek bounds checking
This bug was a result of an annoying corner case around intermingling
signed and unsigned offsets. The boundary check that prevents seeking
a file to a position before the file was preventing valid seeks with
positive offsets.
This corner case is a bit more complicated than it looks because the
offset is signed, while the size of the file is unsigned. Simply
casting both to signed or unsigned offsets won't handle large files.
Diffstat (limited to 'lfs.c')
-rw-r--r-- | lfs.c | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -1635,13 +1635,13 @@ lfs_soff_t lfs_file_seek(lfs_t *lfs, lfs_file_t *file, if (whence == LFS_SEEK_SET) { file->pos = off; } else if (whence == LFS_SEEK_CUR) { - if ((lfs_off_t)-off > file->pos) { + if (off < 0 && (lfs_off_t)-off > file->pos) { return LFS_ERR_INVAL; } file->pos = file->pos + off; } else if (whence == LFS_SEEK_END) { - if ((lfs_off_t)-off > file->size) { + if (off < 0 && (lfs_off_t)-off > file->size) { return LFS_ERR_INVAL; } |