From: Florian Forster Date: Tue, 9 Oct 2018 07:06:57 +0000 (+0200) Subject: write_stackdriver plugin: Check message for NULL before calling strdup(). X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=157437f4e1d1f167480521b2a338169a7a553ef2;p=collectd.git write_stackdriver plugin: Check message for NULL before calling strdup(). --- diff --git a/src/write_stackdriver.c b/src/write_stackdriver.c index 7be3c678..9d06c250 100644 --- a/src/write_stackdriver.c +++ b/src/write_stackdriver.c @@ -139,14 +139,17 @@ static api_error_t *parse_api_error(char const *body) { yajl_val code = yajl_tree_get(root, (char const *[]){"error", "code", NULL}, yajl_t_number); - if (code != NULL) { + if (YAJL_IS_INTEGER(code)) { err->code = YAJL_GET_INTEGER(code); } yajl_val message = yajl_tree_get( root, (char const *[]){"error", "message", NULL}, yajl_t_string); - if (message != NULL) { - err->message = strdup(YAJL_GET_STRING(message)); + if (YAJL_IS_STRING(message)) { + char const *m = YAJL_GET_STRING(message); + if (m != NULL) { + err->message = strdup(m); + } } return err;