mirror of
https://github.com/micropython/micropython.git
synced 2026-01-04 11:10:14 +01:00
extmod/vfs_blockdev: Check return type is an integer.
This catches cases where the return type is not a small int, eg it could be a string, or even a big integer. Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
@@ -69,7 +69,7 @@ static int mp_vfs_blockdev_call_rw(mp_obj_t *args, size_t block_num, size_t bloc
|
||||
// and negative integer on errors. Check for positive integer
|
||||
// results as some callers (i.e. littlefs) will produce corrupt
|
||||
// results from these.
|
||||
int i = MP_OBJ_SMALL_INT_VALUE(ret);
|
||||
int i = mp_obj_get_int(ret);
|
||||
return i > 0 ? (-MP_EINVAL) : i;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,8 +70,8 @@ def test(vfs_class):
|
||||
try:
|
||||
with fs.open("test", "r") as f:
|
||||
print("opened")
|
||||
except OSError as e:
|
||||
print("OSError", e)
|
||||
except Exception as e:
|
||||
print(type(e), e)
|
||||
|
||||
# This variant should succeed on open, may fail on read
|
||||
# unless the filesystem cached the contents already
|
||||
@@ -81,8 +81,8 @@ def test(vfs_class):
|
||||
bdev.read_res = res
|
||||
print("read 1", f.read(1))
|
||||
print("read rest", f.read())
|
||||
except OSError as e:
|
||||
print("OSError", e)
|
||||
except Exception as e:
|
||||
print(type(e), e)
|
||||
|
||||
|
||||
test(vfs.VfsLfs2)
|
||||
|
||||
@@ -2,27 +2,27 @@
|
||||
opened
|
||||
read 1 a
|
||||
read rest aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
OSError [Errno 5] EIO
|
||||
<class 'OSError'> [Errno 5] EIO
|
||||
read 1 a
|
||||
read rest aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
OSError [Errno 22] EINVAL
|
||||
<class 'OSError'> [Errno 22] EINVAL
|
||||
read 1 a
|
||||
read rest aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
OSError [Errno 22] EINVAL
|
||||
<class 'OSError'> [Errno 22] EINVAL
|
||||
read 1 a
|
||||
read rest aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
OSError [Errno 22] EINVAL
|
||||
<class 'TypeError'> can't convert str to int
|
||||
read 1 a
|
||||
read rest aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
<class 'VfsFat'>
|
||||
opened
|
||||
read 1 a
|
||||
read rest aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
OSError [Errno 5] EIO
|
||||
OSError [Errno 5] EIO
|
||||
OSError [Errno 5] EIO
|
||||
OSError [Errno 5] EIO
|
||||
OSError [Errno 5] EIO
|
||||
OSError [Errno 5] EIO
|
||||
OSError [Errno 5] EIO
|
||||
OSError [Errno 5] EIO
|
||||
<class 'OSError'> [Errno 5] EIO
|
||||
<class 'OSError'> [Errno 5] EIO
|
||||
<class 'OSError'> [Errno 5] EIO
|
||||
<class 'OSError'> [Errno 5] EIO
|
||||
<class 'OSError'> [Errno 5] EIO
|
||||
<class 'OSError'> [Errno 5] EIO
|
||||
<class 'TypeError'> can't convert str to int
|
||||
<class 'TypeError'> can't convert str to int
|
||||
|
||||
Reference in New Issue
Block a user