aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2016-07-01 13:47:46 +0200
committerMichael S. Tsirkin <mst@redhat.com>2016-07-04 16:49:33 +0300
commit58e19e6e7914354242a67442d0006f9e31684d1a (patch)
tree30f96c226f88deface835a5a3a2dd90134f5e1a5
parent5178ecd86367090a59af0e15e67cee6f673aaa08 (diff)
log: Clean up misuse of Range for -dfilter
Range encodes an integer interval [a,b] as { begin = a, end = b + 1 }, where a \in [0,2^64-1] and b \in [1,2^64]. Thus, zero end is to be interpreted as 2^64. The implementation of -dfilter (commit 3514552) uses Range differently: it encodes [a,b] as { begin = a, end = b }. The code works, but it contradicts the specification of Range in range.h. Switch to the specified representation. Since it can't represent [0,UINT64_MAX], we have to reject that now. Add a test for it. While we're rejecting anyway: observe that we reject -dfilter LOB..UPB where LOB > UPB when UPB is zero, but happily create an empty Range when it isn't. Reject it then, too, and add a test for it. While there, add a positive test for the problematic upper bound UINT64_MAX. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
-rw-r--r--tests/test-logging.c10
-rw-r--r--util/log.c28
2 files changed, 25 insertions, 13 deletions
diff --git a/tests/test-logging.c b/tests/test-logging.c
index 440e75f5db..b6fa94ee35 100644
--- a/tests/test-logging.c
+++ b/tests/test-logging.c
@@ -68,6 +68,16 @@ static void test_parse_range(void)
g_assert(qemu_log_in_addr_range(0x2050));
g_assert(qemu_log_in_addr_range(0x3050));
+ qemu_set_dfilter_ranges("0xffffffffffffffff-1", &error_abort);
+ g_assert(qemu_log_in_addr_range(UINT64_MAX));
+ g_assert_false(qemu_log_in_addr_range(UINT64_MAX - 1));
+
+ qemu_set_dfilter_ranges("0..0xffffffffffffffff", &err);
+ error_free_or_abort(&err);
+
+ qemu_set_dfilter_ranges("2..1", &err);
+ error_free_or_abort(&err);
+
qemu_set_dfilter_ranges("0x1000+onehundred", &err);
error_free_or_abort(&err);
diff --git a/util/log.c b/util/log.c
index 32e416051c..f811d6163b 100644
--- a/util/log.c
+++ b/util/log.c
@@ -131,8 +131,8 @@ bool qemu_log_in_addr_range(uint64_t addr)
if (debug_regions) {
int i = 0;
for (i = 0; i < debug_regions->len; i++) {
- struct Range *range = &g_array_index(debug_regions, Range, i);
- if (addr >= range->begin && addr <= range->end) {
+ Range *range = &g_array_index(debug_regions, Range, i);
+ if (addr >= range->begin && addr <= range->end - 1) {
return true;
}
}
@@ -158,7 +158,7 @@ void qemu_set_dfilter_ranges(const char *filter_spec, Error **errp)
for (i = 0; ranges[i]; i++) {
const char *r = ranges[i];
const char *range_op, *r2, *e;
- uint64_t r1val, r2val;
+ uint64_t r1val, r2val, lob, upb;
struct Range range;
range_op = strstr(r, "-");
@@ -187,27 +187,29 @@ void qemu_set_dfilter_ranges(const char *filter_spec, Error **errp)
(int)(r2 - range_op), range_op);
goto out;
}
- if (r2val == 0) {
- error_setg(errp, "Invalid range");
- goto out;
- }
switch (*range_op) {
case '+':
- range.begin = r1val;
- range.end = r1val + (r2val - 1);
+ lob = r1val;
+ upb = r1val + r2val - 1;
break;
case '-':
- range.end = r1val;
- range.begin = r1val - (r2val - 1);
+ upb = r1val;
+ lob = r1val - (r2val - 1);
break;
case '.':
- range.begin = r1val;
- range.end = r2val;
+ lob = r1val;
+ upb = r2val;
break;
default:
g_assert_not_reached();
}
+ if (lob > upb || (lob == 0 && upb == UINT64_MAX)) {
+ error_setg(errp, "Invalid range");
+ goto out;
+ }
+ range.begin = lob;
+ range.end = upb + 1;
g_array_append_val(debug_regions, range);
}
out: