Browse code

bb6111 - check return value of lseek in libclamunrar_iface

Shawn Webb authored on 2013/03/02 00:02:24
Showing 1 changed files
... ...
@@ -144,6 +144,10 @@ static unrar_fileheader_t *read_block(int fd, header_type hdr_type)
144 144
 
145 145
     for (;;) {
146 146
 	offset = lseek(fd, 0, SEEK_CUR);
147
+    if (offset == -1) {
148
+        unrar_dbgmsg("UNRAR: seek: call to lseek() failed in read_block\n");
149
+        return NULL;
150
+    }
147 151
 	file_header = read_header(fd, FILE_HEAD);
148 152
 	if(!file_header)
149 153
 	    return NULL;
... ...
@@ -310,6 +314,13 @@ int unrar_open(int fd, const char *dirname, unrar_state_t *state)
310 310
 	unrar_comment_header_t *comment_header;
311 311
 	unrar_dbgmsg("UNRAR: RAR main comment\n");
312 312
 	offset = lseek(fd, 0, SEEK_CUR);
313
+    if (offset == -1) {
314
+        unrar_dbgmsg("UNRAR: seek: lseek() call failed in unrar_open\n");
315
+        free(main_hdr);
316
+        free(state->comment_dir);
317
+        free(unpack_data);
318
+        return UNRAR_ERR;
319
+    }
313 320
 	unrar_dbgmsg("UNRAR: Offset: %x\n", offset);
314 321
 	if(offset < 0){
315 322
 	    unrar_dbgmsg("UNRAR: Error Offset: %d\n", offset);
... ...
@@ -352,7 +363,17 @@ int unrar_open(int fd, const char *dirname, unrar_state_t *state)
352 352
 	    }
353 353
 	    free(comment_header);
354 354
 	}
355
-	lseek(fd, offset, SEEK_SET);
355
+	if (lseek(fd, offset, SEEK_SET) == -1) {
356
+        unrar_dbgmsg("UNRAR: seek: call to lseek() failed in unrar_open: %ld\n", offset);
357
+        free(main_hdr);
358
+        free(comment_header);
359
+        ppm_destructor(&unpack_data->ppm_data);
360
+        rar_init_filters(unpack_data);
361
+        unpack_free_data(unpack_data);
362
+        free(unpack_data);
363
+        free(state->comment_dir);
364
+        return UNRAR_ERR;
365
+    }
356 366
     }
357 367
 
358 368
     if(main_hdr->head_size > SIZEOF_NEWMHD) {