Matej Habrnal 3674e6
From de667f35fe7fd1d4a5fde8f5d0419387c33db9a2 Mon Sep 17 00:00:00 2001
Matej Habrnal 3674e6
From: Jakub Filak <jfilak@redhat.com>
Matej Habrnal 3674e6
Date: Tue, 11 Aug 2015 10:01:53 +0200
Matej Habrnal 3674e6
Subject: [PATCH] cli: fix testing of DBus API return codes
Matej Habrnal 3674e6
Matej Habrnal 3674e6
The DBus wrapper functions uses ERR_PTR to report an error, so the
Matej Habrnal 3674e6
callers has to test the returned pointers for NULL and for ERR_PTR.
Matej Habrnal 3674e6
Matej Habrnal 3674e6
Related: rhbz#1224984
Matej Habrnal 3674e6
Matej Habrnal 3674e6
Signed-off-by: Jakub Filak <jfilak@redhat.com>
Matej Habrnal 3674e6
---
Matej Habrnal 3674e6
 src/cli/list.c   | 3 +++
Matej Habrnal 3674e6
 src/cli/status.c | 5 ++++-
Matej Habrnal 3674e6
 2 files changed, 7 insertions(+), 1 deletion(-)
Matej Habrnal 3674e6
Matej Habrnal 3674e6
diff --git a/src/cli/list.c b/src/cli/list.c
Matej Habrnal 3674e6
index 68dda47..d069695 100644
Matej Habrnal 3674e6
--- a/src/cli/list.c
Matej Habrnal 3674e6
+++ b/src/cli/list.c
Matej Habrnal 3674e6
@@ -36,6 +36,9 @@ static problem_data_t *load_problem_data(const char *problem_id)
Matej Habrnal 3674e6
 
Matej Habrnal 3674e6
     /* First, check if there is a problem with the passed id */
Matej Habrnal 3674e6
     GList *problems = get_problems_over_dbus(g_cli_authenticate);
Matej Habrnal 3674e6
+    if (problems == ERR_PTR)
Matej Habrnal 3674e6
+        return NULL;
Matej Habrnal 3674e6
+
Matej Habrnal 3674e6
     GList *item = g_list_find_custom(problems, problem_id, (GCompareFunc)strcmp);
Matej Habrnal 3674e6
 
Matej Habrnal 3674e6
     /* (git requires at least 5 char hash prefix, we do the same) */
Matej Habrnal 3674e6
diff --git a/src/cli/status.c b/src/cli/status.c
Matej Habrnal 3674e6
index 0635289..3620cea 100644
Matej Habrnal 3674e6
--- a/src/cli/status.c
Matej Habrnal 3674e6
+++ b/src/cli/status.c
Matej Habrnal 3674e6
@@ -27,6 +27,9 @@ static unsigned int count_problem_dirs(unsigned long since)
Matej Habrnal 3674e6
     unsigned count = 0;
Matej Habrnal 3674e6
 
Matej Habrnal 3674e6
     GList *problems = get_problems_over_dbus(g_cli_authenticate);
Matej Habrnal 3674e6
+    if (problems == ERR_PTR)
Matej Habrnal 3674e6
+        return count;
Matej Habrnal 3674e6
+
Matej Habrnal 3674e6
     for (GList *iter = problems; iter != NULL; iter = g_list_next(iter))
Matej Habrnal 3674e6
     {
Matej Habrnal 3674e6
         const char *problem_id = (const char *)iter->data;
Matej Habrnal 3674e6
@@ -37,7 +40,7 @@ static unsigned int count_problem_dirs(unsigned long since)
Matej Habrnal 3674e6
         }
Matej Habrnal 3674e6
 
Matej Habrnal 3674e6
         char *time_str = load_text_over_dbus(problem_id, FILENAME_LAST_OCCURRENCE);
Matej Habrnal 3674e6
-        if (time_str == NULL)
Matej Habrnal 3674e6
+        if (time_str == ERR_PTR || time_str == NULL)
Matej Habrnal 3674e6
         {
Matej Habrnal 3674e6
             log_debug("Not counting problem %s: failed to get time element", problem_id);
Matej Habrnal 3674e6
             continue;
Matej Habrnal 3674e6
-- 
Matej Habrnal 3674e6
2.4.3
Matej Habrnal 3674e6