aboutsummaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
authorFrediano Ziglio <freddy77@gmail.com>2011-09-10 10:23:56 +0200
committerKevin Wolf <kwolf@redhat.com>2011-09-12 15:17:22 +0200
commitee18e730234792b33e01d47939f4c30f29c9744e (patch)
tree8eac1cbd5b066ebf81744ac073e0840c85336d85 /block
parentdea43a65d6b09c43cc7df94f76bb7522016318f4 (diff)
qcow2: fix range check
QCowL2Meta::offset is not cluster aligned but only sector aligned however nb_clusters count cluster from cluster start. This fix range check. Note that old code have no corruption issues related to this check cause it only cause intersection to occur when shouldn't. Signed-off-by: Frediano Ziglio <freddy77@gmail.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block')
-rw-r--r--block/qcow2-cluster.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index 428b5ad5e8..2f76311354 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -776,17 +776,17 @@ again:
*/
QLIST_FOREACH(old_alloc, &s->cluster_allocs, next_in_flight) {
- uint64_t end_offset = offset + nb_clusters * s->cluster_size;
- uint64_t old_offset = old_alloc->offset;
- uint64_t old_end_offset = old_alloc->offset +
- old_alloc->nb_clusters * s->cluster_size;
+ uint64_t start = offset >> s->cluster_bits;
+ uint64_t end = start + nb_clusters;
+ uint64_t old_start = old_alloc->offset >> s->cluster_bits;
+ uint64_t old_end = old_start + old_alloc->nb_clusters;
- if (end_offset < old_offset || offset > old_end_offset) {
+ if (end < old_start || start > old_end) {
/* No intersection */
} else {
- if (offset < old_offset) {
+ if (start < old_start) {
/* Stop at the start of a running allocation */
- nb_clusters = (old_offset - offset) >> s->cluster_bits;
+ nb_clusters = old_start - start;
} else {
nb_clusters = 0;
}