diff -rupN xen-unstable.hg-3.0.5-pre-14797.orig/tools/blktap/drivers/blktapctrl.c xen-unstable.hg-3.0.5-pre-14797.new/tools/blktap/drivers/blktapctrl.c
--- xen-unstable.hg-3.0.5-pre-14797.orig/tools/blktap/drivers/blktapctrl.c 2007-04-11 19:10:30.000000000 -0400
+++ xen-unstable.hg-3.0.5-pre-14797.new/tools/blktap/drivers/blktapctrl.c 2007-04-13 11:32:14.000000000 -0400
@@ -673,7 +673,10 @@ int main(int argc, char *argv[])
__init_blkif();
snprintf(buf, sizeof(buf), "BLKTAPCTRL[%d]", getpid());
openlog(buf, LOG_CONS|LOG_ODELAY, LOG_DAEMON);
- daemon(0,0);
+ if (daemon(0,0) < 0) {
+ DPRINTF("could not go into daemon mode\n");
+ return -1;
+ }
print_drivers();
init_driver_list();
diff -rupN xen-unstable.hg-3.0.5-pre-14797.orig/tools/blktap/drivers/block-aio.c xen-unstable.hg-3.0.5-pre-14797.new/tools/blktap/drivers/block-aio.c
--- xen-unstable.hg-3.0.5-pre-14797.orig/tools/blktap/drivers/block-aio.c 2007-04-13 11:32:01.000000000 -0400
+++ xen-unstable.hg-3.0.5-pre-14797.new/tools/blktap/drivers/block-aio.c 2007-04-13 11:33:22.000000000 -0400
@@ -203,13 +203,27 @@ int tdaio_open (struct disk_driver *dd,
prv->fd = fd;
- pipe(prv->command_fd);
- pipe(prv->completion_fd);
-
- ret = pthread_create(&prv->aio_thread, NULL,
- tdaio_completion_thread, prv);
- ret = 0;
- write(prv->command_fd[1], &ret, sizeof(ret));
+ if ((ret = pipe(prv->command_fd)) < 0) {
+ DPRINTF("Unable to create command pipe\n");
+ goto done;
+ }
+ if ((ret = pipe(prv->completion_fd)) < 0) {
+ DPRINTF("Unable to create completion pipe\n");
+ goto done;
+ }
+
+ if ((ret = pthread_create(&prv->aio_thread, NULL,
+ tdaio_completion_thread, prv)) != 0) {
+ ret = -1;
+ DPRINTF("Unable to create completion thread\n");
+ goto done;
+ }
+ ret = 0;
+ if (write(prv->command_fd[1], &ret, sizeof(ret)) < 0) {
+ ret = -1;
+ DPRINTF("Cannot initialize command pipe\n");
+ goto done;
+ }
init_fds(dd);
ret = get_image_info(s, fd);
@@ -382,7 +396,10 @@ repeat:
goto repeat;
}
- write(prv->command_fd[1], &nr_events, sizeof(nr_events));
+ if (write(prv->command_fd[1], &nr_events, sizeof(nr_events)) < 0) {
+ DPRINTF("cannot send events command\n");
+ return -1;
+ }
return rsp;
}
diff -rupN xen-unstable.hg-3.0.5-pre-14797.orig/tools/blktap/drivers/block-qcow.c xen-unstable.hg-3.0.5-pre-14797.new/tools/blktap/drivers/block-qcow.c
--- xen-unstable.hg-3.0.5-pre-14797.orig/tools/blktap/drivers/block-qcow.c 2007-04-11 19:10:30.000000000 -0400
+++ xen-unstable.hg-3.0.5-pre-14797.new/tools/blktap/drivers/block-qcow.c 2007-04-13 11:36:55.000000000 -0400
@@ -707,7 +707,10 @@ found:
}
memcpy(tmp_ptr2, l2_ptr, 4096);
lseek(s->fd, l2_offset + (l2_sector << 12), SEEK_SET);
- write(s->fd, tmp_ptr2, 4096);
+ if (write(s->fd, tmp_ptr2, 4096) < 0) {
+ free(tmp_ptr2);
+ return -1;
+ }
free(tmp_ptr2);
}
return cluster_offset;
@@ -1112,20 +1115,26 @@ int tdqcow_close(struct disk_driver *dd)
{
struct tdqcow_state *s = (struct tdqcow_state *)dd->private;
uint32_t cksum, out;
- int fd, offset;
+ int fd, offset, ret = 0;
/*Update the hdr cksum*/
if(s->min_cluster_alloc == s->l2_size) {
cksum = gen_cksum((char *)s->l1_table, s->l1_size * sizeof(uint64_t));
printf("Writing cksum: %d",cksum);
- fd = open(s->name, O_WRONLY | O_LARGEFILE); /*Open without O_DIRECT*/
+ if ((fd = open(s->name, O_WRONLY | O_LARGEFILE)) < 0) { /*Open without O_DIRECT*/
+ ret = -1;
+ goto cleanup;
+ }
offset = sizeof(QCowHeader) + sizeof(uint32_t);
lseek(fd, offset, SEEK_SET);
out = cpu_to_be32(cksum);
- write(fd, &out, sizeof(uint32_t));
+ if ((ret = write(fd, &out, sizeof(uint32_t))) < 0) {
+ ret = -1;
+ }
close(fd);
}
+ cleanup:
io_destroy(s->aio_ctx);
free(s->name);
free(s->l1_table);
@@ -1212,7 +1221,9 @@ int qcow_create(const char *filename, ui
strncpy(backing_filename, backing_file,
sizeof(backing_filename));
} else {
- realpath(backing_file, backing_filename);
+ if (!realpath(backing_file, backing_filename)) {
+ return -1;
+ }
if (stat(backing_filename, &st) != 0) {
return -1;
}
diff -rupN xen-unstable.hg-3.0.5-pre-14797.orig/tools/blktap/drivers/block-vmdk.c xen-unstable.hg-3.0.5-pre-14797.new/tools/blktap/drivers/block-vmdk.c
--- xen-unstable.hg-3.0.5-pre-14797.orig/tools/blktap/drivers/block-vmdk.c 2007-04-11 19:10:30.000000000 -0400
+++ xen-unstable.hg-3.0.5-pre-14797.new/tools/blktap/drivers/block-vmdk.c 2007-04-13 11:32:14.000000000 -0400
@@ -283,8 +283,10 @@ static uint64_t get_cluster_offset(struc
if (!allocate)
return 0;
cluster_offset = lseek(prv->fd, 0, SEEK_END);
- ftruncate(prv->fd, cluster_offset +
- (prv->cluster_sectors << 9));
+ if (ftruncate(prv->fd, cluster_offset +
+ (prv->cluster_sectors << 9)) < 0) {
+ return 0;
+ }
cluster_offset >>= 9;
/* update L2 table */
tmp = cpu_to_le32(cluster_offset);