[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 14/20] qapi: Assert non-input visitors see only valid narrow integ
From: |
Markus Armbruster |
Subject: |
[PULL 14/20] qapi: Assert non-input visitors see only valid narrow integers |
Date: |
Thu, 30 Apr 2020 07:30:58 +0200 |
visit_type_intN() and visit_type_uintN() fail when the value is out of
bounds.
This is appropriate with an input visitor: the value comes from input,
and input may be bad.
It should never happen with the other visitors: the value comes from
the caller, and callers must keep it within bounds. Assert that.
Signed-off-by: Markus Armbruster <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Message-Id: <address@hidden>
---
qapi/qapi-visit-core.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c
index 80ca83bcb9..74aa9c04bd 100644
--- a/qapi/qapi-visit-core.c
+++ b/qapi/qapi-visit-core.c
@@ -160,10 +160,13 @@ static void visit_type_uintN(Visitor *v, uint64_t *obj,
const char *name,
Error *err = NULL;
uint64_t value = *obj;
+ assert(v->type == VISITOR_INPUT || value <= max);
+
v->type_uint64(v, name, &value, &err);
if (err) {
error_propagate(errp, err);
} else if (value > max) {
+ assert(v->type == VISITOR_INPUT);
error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
name ? name : "null", type);
} else {
@@ -219,10 +222,13 @@ static void visit_type_intN(Visitor *v, int64_t *obj,
const char *name,
Error *err = NULL;
int64_t value = *obj;
+ assert(v->type == VISITOR_INPUT || (value >= min && value <= max));
+
v->type_int64(v, name, &value, &err);
if (err) {
error_propagate(errp, err);
} else if (value < min || value > max) {
+ assert(v->type == VISITOR_INPUT);
error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
name ? name : "null", type);
} else {
--
2.21.1
- [PULL 00/20] QAPI patches for 2020-04-30, Markus Armbruster, 2020/04/30
- [PULL 01/20] qobject: Clean up QLIST_FOREACH_ENTRY(), Markus Armbruster, 2020/04/30
- [PULL 03/20] qobject: Eliminate qlist_iter(), use QLIST_FOREACH_ENTRY() instead, Markus Armbruster, 2020/04/30
- [PULL 02/20] qobject: Factor out helper json_pretty_newline(), Markus Armbruster, 2020/04/30
- [PULL 08/20] qapi: Fix typo in visit_start_list()'s contract, Markus Armbruster, 2020/04/30
- [PULL 09/20] qapi: Document @errp usage more thoroughly in visitor.h, Markus Armbruster, 2020/04/30
- [PULL 12/20] qapi: Fix Visitor contract for start_alternate(), Markus Armbruster, 2020/04/30
- [PULL 11/20] qapi: Assert incomplete object occurs only in dealloc visitor, Markus Armbruster, 2020/04/30
- [PULL 10/20] qapi: Polish prose in visitor.h, Markus Armbruster, 2020/04/30
- [PULL 14/20] qapi: Assert non-input visitors see only valid narrow integers,
Markus Armbruster <=
- [PULL 20/20] qapi: Generate simpler marshalling code when no arguments, Markus Armbruster, 2020/04/30
- [PULL 04/20] qobject: Eliminate qdict_iter(), use qdict_first(), qdict_next(), Markus Armbruster, 2020/04/30
- [PULL 05/20] qemu-option: Clean up after the previous commit, Markus Armbruster, 2020/04/30
- [PULL 06/20] qapi: Belatedly update visitor.h's big comment for QAPI modules, Markus Armbruster, 2020/04/30
- [PULL 13/20] qapi: Assert output visitors see only valid enum values, Markus Armbruster, 2020/04/30
- [PULL 18/20] qom: Simplify object_property_get_enum(), Markus Armbruster, 2020/04/30
- [PULL 16/20] qapi: Assert non-input visitors see only valid alternate tags, Markus Armbruster, 2020/04/30
- [PULL 15/20] qapi: Clean up visitor's recovery from input with invalid type, Markus Armbruster, 2020/04/30
- [PULL 07/20] qapi: Fix the virtual walk example in visitor.h's big comment, Markus Armbruster, 2020/04/30
- [PULL 19/20] qapi: Disallow qmp_marshal_FOO(NULL, ...), Markus Armbruster, 2020/04/30