Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/littlefs-project/littlefs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lfs.c
diff options
context:
space:
mode:
authorChristopher Haster <chaster@utexas.edu>2018-01-04 00:00:04 +0300
committerChristopher Haster <chaster@utexas.edu>2018-01-04 00:00:04 +0300
commitaea3d3db46634bf26298c8df0be020c03b80daba (patch)
tree419e29313c61583acb494ae125b8fdf6290f73cd /lfs.c
parentbe22d3449f23a24e7462114349ce04d751e42437 (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.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/lfs.c b/lfs.c
index 2d0e331..4267d7c 100644
--- a/lfs.c
+++ b/lfs.c
@@ -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;
}