Commit f332e830 authored by Markus Armbruster's avatar Markus Armbruster
Browse files

qapi: Make string input and opts visitor require non-null input



The string input visitor tries to cope with null input.  Null input
isn't used anywhere, and isn't covered by tests.  Unsurprisingly, it
doesn't fully work: start_list() crashes because it passes the input
via parse_str() to strtoll() unchecked.

Make string_input_visitor_new() assert its argument isn't null, and
drop the code trying to deal with null input.

The opts visitor crashes when you try to actually visit something with
null input.  Make opts_visitor_new() assert its argument isn't null,
mostly for clarity.

qobject_input_visitor_new() already asserts its argument isn't null.

Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
Reviewed-by: default avatarEric Blake <eblake@redhat.com>
Message-Id: <1488544368-30622-17-git-send-email-armbru@redhat.com>
parent a8aec6de
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -528,6 +528,7 @@ opts_visitor_new(const QemuOpts *opts)
{
    OptsVisitor *ov;

    assert(opts);
    ov = g_malloc0(sizeof *ov);

    ov->visitor.type = VISITOR_INPUT;
+17 −37
Original line number Diff line number Diff line
@@ -182,12 +182,6 @@ static void parse_type_int64(Visitor *v, const char *name, int64_t *obj,
{
    StringInputVisitor *siv = to_siv(v);

    if (!siv->string) {
        error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
                   "integer");
        return;
    }

    if (parse_str(siv, name, errp) < 0) {
        return;
    }
@@ -242,13 +236,7 @@ static void parse_type_size(Visitor *v, const char *name, uint64_t *obj,
    Error *err = NULL;
    uint64_t val;

    if (siv->string) {
    parse_option_size(name, siv->string, &val, &err);
    } else {
        error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
                   "size");
        return;
    }
    if (err) {
        error_propagate(errp, err);
        return;
@@ -262,7 +250,6 @@ static void parse_type_bool(Visitor *v, const char *name, bool *obj,
{
    StringInputVisitor *siv = to_siv(v);

    if (siv->string) {
    if (!strcasecmp(siv->string, "on") ||
        !strcasecmp(siv->string, "yes") ||
        !strcasecmp(siv->string, "true")) {
@@ -275,7 +262,6 @@ static void parse_type_bool(Visitor *v, const char *name, bool *obj,
        *obj = false;
        return;
    }
    }

    error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
               "boolean");
@@ -285,13 +271,8 @@ static void parse_type_str(Visitor *v, const char *name, char **obj,
                           Error **errp)
{
    StringInputVisitor *siv = to_siv(v);
    if (siv->string) {

    *obj = g_strdup(siv->string);
    } else {
        *obj = NULL;
        error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
                   "string");
    }
}

static void parse_type_number(Visitor *v, const char *name, double *obj,
@@ -302,10 +283,8 @@ static void parse_type_number(Visitor *v, const char *name, double *obj,
    double val;

    errno = 0;
    if (siv->string) {
    val = strtod(siv->string, &endp);
    }
    if (!siv->string || errno || endp == siv->string || *endp) {
    if (errno || endp == siv->string || *endp) {
        error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
                   "number");
        return;
@@ -327,6 +306,7 @@ Visitor *string_input_visitor_new(const char *str)
{
    StringInputVisitor *v;

    assert(str);
    v = g_malloc0(sizeof(*v));

    v->visitor.type = VISITOR_INPUT;