all: Check for return value of lseek
This commit is contained in:
1 parent
1ee86c05f4
commit
b7f80de25d
5 files changed
+47
-9
No files matched your search
@@ -92,7 +92,8 @@ int cal_init_file(const char * file, struct cal ** cal_out) {
|
|||||||
blksize = lseek(fd, 0, SEEK_END);
|
blksize = lseek(fd, 0, SEEK_END);
|
||||||
if ( blksize == (off_t)-1 )
|
if ( blksize == (off_t)-1 )
|
||||||
goto err;
|
goto err;
|
||||||
lseek(fd, 0, SEEK_SET);
|
if ( lseek(fd, 0, SEEK_SET) == (off_t)-1 )
|
||||||
|
goto err;
|
||||||
#endif
|
#endif
|
||||||
if ( blksize > SSIZE_MAX )
|
if ( blksize > SSIZE_MAX )
|
||||||
goto err;
|
goto err;
|
||||||
|
|||||||
+4
-1
@@ -185,7 +185,10 @@ int disk_dump_dev(int fd, const char * file) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
lseek(fd, 0, SEEK_SET);
|
if ( lseek(fd, 0, SEEK_SET) == (off_t)-1 ) {
|
||||||
|
ERROR_INFO("Cannot seek to begin of block device");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -218,6 +218,8 @@ struct fiasco * fiasco_alloc_from_file(const char * file) {
|
|||||||
READ_OR_RETURN(fiasco, buf, 1);
|
READ_OR_RETURN(fiasco, buf, 1);
|
||||||
|
|
||||||
offset = lseek(fiasco->fd, 0, SEEK_CUR);
|
offset = lseek(fiasco->fd, 0, SEEK_CUR);
|
||||||
|
if ( offset == (off_t)-1 )
|
||||||
|
FIASCO_READ_ERROR(fiasco, "Cannot get offset of file");
|
||||||
|
|
||||||
VERBOSE(" version: %s\n", version);
|
VERBOSE(" version: %s\n", version);
|
||||||
VERBOSE(" device: %s\n", device);
|
VERBOSE(" device: %s\n", device);
|
||||||
@@ -231,7 +233,8 @@ struct fiasco * fiasco_alloc_from_file(const char * file) {
|
|||||||
|
|
||||||
fiasco_add_image(fiasco, image);
|
fiasco_add_image(fiasco, image);
|
||||||
|
|
||||||
lseek(fiasco->fd, offset+length, SEEK_SET);
|
if ( lseek(fiasco->fd, offset+length, SEEK_SET) == (off_t)-1 )
|
||||||
|
FIASCO_READ_ERROR(fiasco, "Cannot seek to next image in file");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+33
-5
@@ -247,6 +247,7 @@ static struct image * image_alloc(void) {
|
|||||||
|
|
||||||
struct image * image_alloc_from_file(const char * file, const char * type, const char * device, const char * hwrevs, const char * version, const char * layout) {
|
struct image * image_alloc_from_file(const char * file, const char * type, const char * device, const char * hwrevs, const char * version, const char * layout) {
|
||||||
|
|
||||||
|
off_t offset;
|
||||||
struct image * image = image_alloc();
|
struct image * image = image_alloc();
|
||||||
if ( ! image )
|
if ( ! image )
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -259,11 +260,26 @@ struct image * image_alloc_from_file(const char * file, const char * type, const
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
image->size = lseek(image->fd, 0, SEEK_END);
|
offset = lseek(image->fd, 0, SEEK_END);
|
||||||
|
if ( offset == (off_t)-1 ) {
|
||||||
|
ERROR_INFO("Cannot seek to end of file %s", file);
|
||||||
|
close(image->fd);
|
||||||
|
free(image);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
image->size = offset;
|
||||||
image->offset = 0;
|
image->offset = 0;
|
||||||
image->cur = 0;
|
image->cur = 0;
|
||||||
image->orig_filename = strdup(file);
|
image->orig_filename = strdup(file);
|
||||||
lseek(image->fd, 0, SEEK_SET);
|
|
||||||
|
if ( lseek(image->fd, 0, SEEK_SET) == (off_t)-1 ) {
|
||||||
|
ERROR_INFO("Cannot seek to begin of file %s", file);
|
||||||
|
close(image->fd);
|
||||||
|
free(image->orig_filename);
|
||||||
|
free(image);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if ( image_append(image, type, device, hwrevs, version, layout) < 0 )
|
if ( image_append(image, type, device, hwrevs, version, layout) < 0 )
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -331,17 +347,22 @@ void image_free(struct image * image) {
|
|||||||
|
|
||||||
void image_seek(struct image * image, size_t whence) {
|
void image_seek(struct image * image, size_t whence) {
|
||||||
|
|
||||||
|
off_t offset;
|
||||||
|
|
||||||
if ( whence > image->size )
|
if ( whence > image->size )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ( whence >= image->size - image->align ) {
|
if ( whence >= image->size - image->align ) {
|
||||||
lseek(image->fd, image->size - image->align - 1, SEEK_SET);
|
offset = lseek(image->fd, image->size - image->align - 1, SEEK_SET);
|
||||||
image->acur = whence - ( image->size - image->align );
|
image->acur = whence - ( image->size - image->align );
|
||||||
} else {
|
} else {
|
||||||
lseek(image->fd, image->offset + whence, SEEK_SET);
|
offset = lseek(image->fd, image->offset + whence, SEEK_SET);
|
||||||
image->acur = 0;
|
image->acur = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( offset == (off_t)-1 )
|
||||||
|
ERROR_INFO("Seek in file %s failed", (image->orig_filename ? image->orig_filename : "(unknown)"));
|
||||||
|
|
||||||
IMAGE_STORE_CUR(image);
|
IMAGE_STORE_CUR(image);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -350,6 +371,7 @@ size_t image_read(struct image * image, void * buf, size_t count) {
|
|||||||
|
|
||||||
size_t cur;
|
size_t cur;
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
|
off_t offset;
|
||||||
size_t new_count = 0;
|
size_t new_count = 0;
|
||||||
size_t ret_count = 0;
|
size_t ret_count = 0;
|
||||||
|
|
||||||
@@ -376,7 +398,13 @@ size_t image_read(struct image * image, void * buf, size_t count) {
|
|||||||
if ( ret_count == count )
|
if ( ret_count == count )
|
||||||
return ret_count;
|
return ret_count;
|
||||||
|
|
||||||
cur = lseek(image->fd, 0, SEEK_CUR) - image->offset;
|
offset = lseek(image->fd, 0, SEEK_CUR);
|
||||||
|
if ( offset == (off_t)-1 ) {
|
||||||
|
ERROR_INFO("Cannot get offset of file %s", (image->orig_filename ? image->orig_filename : "(unknown)"));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
cur = offset - image->offset;
|
||||||
|
|
||||||
if ( image->align && cur == image->size - image->align && image->acur < image->align ) {
|
if ( image->align && cur == image->size - image->align && image->acur < image->align ) {
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -212,7 +212,10 @@ static void parse_image_arg(char * arg, struct image_list ** image_first) {
|
|||||||
ERROR_INFO("Cannot get size of file %s", layout_file);
|
ERROR_INFO("Cannot get size of file %s", layout_file);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
lseek(fd, 0, SEEK_SET);
|
if ( lseek(fd, 0, SEEK_SET) == (off_t)-1 ) {
|
||||||
|
ERROR_INFO("Cannot seek to begin of file %s", layout_file);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
layout = malloc(len+1);
|
layout = malloc(len+1);
|
||||||
if ( ! layout ) {
|
if ( ! layout ) {
|
||||||
ALLOC_ERROR();
|
ALLOC_ERROR();
|
||||||
|
|||||||
Reference in new issue
Block a user