Пример #1
0
/* Attempts to parse the content of 'rpc->parser' (which is complete JSON) as a
 * JSON-RPC message.  If successful, returns the JSON-RPC message.  On failure,
 * signals an error on 'rpc' with jsonrpc_error() and returns NULL. */
static struct jsonrpc_msg *
jsonrpc_parse_received_message(struct jsonrpc *rpc)
{
    struct jsonrpc_msg *msg;
    struct json *json;
    char *error;

    json = json_parser_finish(rpc->parser);
    rpc->parser = NULL;
    if (json->type == JSON_STRING) {
        VLOG_WARN_RL(&rl, "%s: error parsing stream: %s",
                     rpc->name, json_string(json));
        jsonrpc_error(rpc, EPROTO);
        json_destroy(json);
        return NULL;
    }

    error = jsonrpc_msg_from_json(json, &msg);
    if (error) {
        VLOG_WARN_RL(&rl, "%s: received bad JSON-RPC message: %s",
                     rpc->name, error);
        free(error);
        jsonrpc_error(rpc, EPROTO);
        return NULL;
    }

    jsonrpc_log_msg(rpc, "received", msg);
    return msg;
}
Пример #2
0
int
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
    if (!size || data[size - 1]) {
        return 0;
    }

    struct json *j1 = json_from_string((const char *)data);
    if (j1->type == JSON_STRING) {
        json_destroy(j1);
        return 0;
    }

    free(json_to_string(j1, JSSF_SORT | JSSF_PRETTY));

    struct jsonrpc_msg *msg;
    char *error = jsonrpc_msg_from_json(j1, &msg); /* Frees 'j1'. */
    if (error) {
        free(error);
        return 0;
    }

    struct json *j2 = jsonrpc_msg_to_json(msg); /* Frees 'msg'. */
    if (j2->type == JSON_STRING) {
        json_destroy(j2);
        return 0;
    }

    free(json_to_string(j2, JSSF_SORT | JSSF_PRETTY));
    json_destroy(j2);

    return 0;
}