diff options
author | Slava Monich <slava.monich@jolla.com> | 2021-07-30 15:07:51 +0300 |
---|---|---|
committer | Denis Kenzior <denkenz@gmail.com> | 2021-07-30 11:07:19 -0500 |
commit | 121448e3785daf68b0f3d4e12967da78fb07388c (patch) | |
tree | 330893caf5aed2ca7ac083884b3a7c771091666d | |
parent | b06759215d38ed89094fcd5253475a5f731e0169 (diff) | |
download | ofono-121448e3785daf68b0f3d4e12967da78fb07388c.tar.gz |
simfs: Fix reads beyond the first block
-rw-r--r-- | src/simfs.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/simfs.c b/src/simfs.c index 3d4f6283..515f5c97 100644 --- a/src/simfs.c +++ b/src/simfs.c @@ -388,13 +388,12 @@ static void sim_fs_op_read_block_cb(const struct ofono_error *error, if (op->current == start_block) { bufoff = 0; dataoff = op->offset % 256; - tocopy = MIN(256 - op->offset % 256, - op->num_bytes - op->current * 256); + tocopy = MIN(256 - dataoff, op->num_bytes); } else { - bufoff = (op->current - start_block - 1) * 256 + + bufoff = (op->current - start_block) * 256 - op->offset % 256; dataoff = 0; - tocopy = MIN(256, op->num_bytes - op->current * 256); + tocopy = MIN(256, op->num_bytes - bufoff); } DBG("bufoff: %d, dataoff: %d, tocopy: %d", @@ -463,13 +462,12 @@ static gboolean sim_fs_op_read_block(gpointer user_data) bufoff = 0; seekoff = SIM_CACHE_HEADER_SIZE + op->current * 256 + op->offset % 256; - toread = MIN(256 - op->offset % 256, - op->num_bytes - op->current * 256); + toread = MIN(256 - op->offset % 256, op->num_bytes); } else { - bufoff = (op->current - start_block - 1) * 256 + + bufoff = (op->current - start_block) * 256 - op->offset % 256; seekoff = SIM_CACHE_HEADER_SIZE + op->current * 256; - toread = MIN(256, op->num_bytes - op->current * 256); + toread = MIN(256, op->num_bytes - bufoff); } DBG("bufoff: %d, seekoff: %d, toread: %d", |