[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tyndur-devel] [PATCH] iso9660: Fehlerbehandlung beim Lesen



! iso9660: Wenn beim Lesen vom Dateisystem etwas schiefgeht, liefert der
  Cache NULL zurueck, was man dann auch pruefen sollte

Signed-off-by: Kevin Wolf <kevin@xxxxxxxxxx>
---
 src/modules/cdi/iso9660/sector.c |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/src/modules/cdi/iso9660/sector.c b/src/modules/cdi/iso9660/sector.c
index 645fb10..5e765ea 100644
--- a/src/modules/cdi/iso9660/sector.c
+++ b/src/modules/cdi/iso9660/sector.c
@@ -26,6 +26,8 @@
 
 #include "iso9660_cdi.h"
 
+#define MIN(a,b) ((a) > (b) ? (b) : (a))
+
 /**
  * Reads data from device for cache
  *  @param cache CDI cache
@@ -56,15 +58,25 @@ size_t iso9660_read(struct iso9660_fs_res *res,size_t pos,size_t size,void *buff
 
   while (rem_size>0) {
     //debug("Block: 0x%x\n",res->data_sector+block++);
-    struct cdi_cache_block *cache_block = cdi_cache_block_get(res->cache,res->data_sector+block++,0);
-    size_t cur_size = rem_size>res->voldesc->sector_size?res->voldesc->sector_size:rem_size;
+    struct cdi_cache_block* cache_block;
+    size_t cur_size;
+
+    cache_block = cdi_cache_block_get(res->cache, res->data_sector + block, 0);
+    if (cache_block == NULL) {
+        break;
+    }
+
+    cur_size = MIN(rem_size, res->voldesc->sector_size);
+
     memcpy(buffer,cache_block->data+offset,cur_size);
     cdi_cache_block_release(res->cache,cache_block);
+
+    block++;
     buffer += cur_size;
     rem_size -= cur_size;
     offset = 0;
   }
 
-  return size;
+  return size - rem_size;
 }
 
-- 
1.6.0.2