write_stackdriver plugin: Check message for NULL before calling strdup().
authorFlorian Forster <octo@collectd.org>
Tue, 9 Oct 2018 07:06:57 +0000 (09:06 +0200)
committerFlorian Forster <octo@collectd.org>
Tue, 9 Oct 2018 07:06:57 +0000 (09:06 +0200)
src/write_stackdriver.c

index 7be3c67..9d06c25 100644 (file)
@@ -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;