Blame SOURCES/0045-SYSDB-Remove-code-causing-a-covscan-warning.patch

9f2ebf
From 075f45980ea004201b2d13a3ecfe3bfb1478046d Mon Sep 17 00:00:00 2001
9f2ebf
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@redhat.com>
9f2ebf
Date: Mon, 13 Nov 2017 08:29:53 +0100
9f2ebf
Subject: [PATCH 45/46] SYSDB: Remove code causing a covscan warning
9f2ebf
MIME-Version: 1.0
9f2ebf
Content-Type: text/plain; charset=UTF-8
9f2ebf
Content-Transfer-Encoding: 8bit
9f2ebf
9f2ebf
There's no reason to check for both ret != EOK and sanitized == NULL, as
9f2ebf
the second should never ever happen.
9f2ebf
9f2ebf
This check is causing a clang warning in our code:
9f2ebf
9f2ebf
 Defect type: CLANG_WARNING
9f2ebf
 1. sssd-1.16.0/src/db/sysdb_ops.c:4223:9: warning: Dereference of undefined pointer value
9f2ebf
 #     if (res->count > 1) {
9f2ebf
 #         ^~~~~~~~~~
9f2ebf
 4. sssd-1.16.0/src/db/sysdb_ops.c:4199:5: note: 'res' declared without an initial value
9f2ebf
 #     struct ldb_result *res;
9f2ebf
 #     ^~~~~~~~~~~~~~~~~~~~~~
9f2ebf
 7. sssd-1.16.0/src/db/sysdb_ops.c:4202:9: note: Assuming 'sid_str' is non-null
9f2ebf
 #     if (!sid_str) return EINVAL;
9f2ebf
 #         ^~~~~~~~
9f2ebf
 10. sssd-1.16.0/src/db/sysdb_ops.c:4202:5: note: Taking false branch
9f2ebf
 #     if (!sid_str) return EINVAL;
9f2ebf
 #     ^
9f2ebf
 13. sssd-1.16.0/src/db/sysdb_ops.c:4205:9: note: Assuming 'tmp_ctx' is non-null
9f2ebf
 #     if (!tmp_ctx) {
9f2ebf
 #         ^~~~~~~~
9f2ebf
 16. sssd-1.16.0/src/db/sysdb_ops.c:4205:5: note: Taking false branch
9f2ebf
 #     if (!tmp_ctx) {
9f2ebf
 #     ^
9f2ebf
 19. sssd-1.16.0/src/db/sysdb_ops.c:4209:11: note: Calling 'sysdb_search_object_by_sid'
9f2ebf
 #     ret = sysdb_search_object_by_sid(tmp_ctx, domain, sid_str, NULL, &res;;
9f2ebf
 #           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9f2ebf
 22. sssd-1.16.0/src/db/sysdb_ops.c:4960:12: note: Calling 'sysdb_search_object_by_str_attr'
9f2ebf
 #     return sysdb_search_object_by_str_attr(mem_ctx, domain, SYSDB_SID_FILTER,
9f2ebf
 #            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9f2ebf
 25. sssd-1.16.0/src/db/sysdb_ops.c:4872:5: note: Taking false branch
9f2ebf
 #     if (str == NULL) {
9f2ebf
 #     ^
9f2ebf
 28. sssd-1.16.0/src/db/sysdb_ops.c:4877:9: note: Assuming 'ret' is equal to 0
9f2ebf
 #     if (ret != EOK || sanitized == NULL) {
9f2ebf
 #         ^~~~~~~~~~
9f2ebf
 31. sssd-1.16.0/src/db/sysdb_ops.c:4877:9: note: Left side of '||' is false
9f2ebf
 32. sssd-1.16.0/src/db/sysdb_ops.c:4877:23: note: Assuming 'sanitized' is equal to null
9f2ebf
 #     if (ret != EOK || sanitized == NULL) {
9f2ebf
 #                       ^~~~~~~~~~~~~~~~~
9f2ebf
 35. sssd-1.16.0/src/db/sysdb_ops.c:4877:5: note: Taking true branch
9f2ebf
 #     if (ret != EOK || sanitized == NULL) {
9f2ebf
 #     ^
9f2ebf
 38. sssd-1.16.0/src/db/sysdb_ops.c:4878:9: note: Left side of '||' is false
9f2ebf
 #         DEBUG(SSSDBG_OP_FAILURE, "sss_filter_sanitize failed.\n");
9f2ebf
 #         ^
9f2ebf
 41. sssd-1.16.0/src/util/debug.h:123:9: note: expanded from macro 'DEBUG'
9f2ebf
 #     if (DEBUG_IS_SET(__debug_macro_level)) { \
9f2ebf
 #         ^
9f2ebf
 44. sssd-1.16.0/src/util/debug.h:135:30: note: expanded from macro 'DEBUG_IS_SET'
9f2ebf
 # #define DEBUG_IS_SET(level) (debug_level & (level) || \
9f2ebf
 #                              ^
9f2ebf
 47. sssd-1.16.0/src/db/sysdb_ops.c:4878:9: note: Assuming 'debug_level' is not equal to 0
9f2ebf
 #         DEBUG(SSSDBG_OP_FAILURE, "sss_filter_sanitize failed.\n");
9f2ebf
 #         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9f2ebf
 50. sssd-1.16.0/src/util/debug.h:123:9: note: expanded from macro 'DEBUG'
9f2ebf
 #     if (DEBUG_IS_SET(__debug_macro_level)) { \
9f2ebf
 #         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9f2ebf
 53. sssd-1.16.0/src/util/debug.h:136:30: note: expanded from macro 'DEBUG_IS_SET'
9f2ebf
 #                             (debug_level == SSSDBG_UNRESOLVED && \
9f2ebf
 #                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9f2ebf
 56. sssd-1.16.0/src/db/sysdb_ops.c:4878:9: note: Left side of '&&' is false
9f2ebf
 57. sssd-1.16.0/src/util/debug.h:123:9: note: expanded from macro 'DEBUG'
9f2ebf
 #     if (DEBUG_IS_SET(__debug_macro_level)) { \
9f2ebf
 #         ^
9f2ebf
 60. sssd-1.16.0/src/util/debug.h:136:63: note: expanded from macro 'DEBUG_IS_SET'
9f2ebf
 #                             (debug_level == SSSDBG_UNRESOLVED && \
9f2ebf
 #                                                               ^
9f2ebf
 63. sssd-1.16.0/src/db/sysdb_ops.c:4878:9: note: Loop condition is false. Exiting loop
9f2ebf
 64. sssd-1.16.0/src/util/debug.h:121:35: note: expanded from macro 'DEBUG'
9f2ebf
 # #define DEBUG(level, format, ...) do { \
9f2ebf
 #                                   ^
9f2ebf
 67. sssd-1.16.0/src/db/sysdb_ops.c:4879:9: note: Control jumps to line 4892
9f2ebf
 #         goto done;
9f2ebf
 #         ^
9f2ebf
 70. sssd-1.16.0/src/db/sysdb_ops.c:4960:12: note: Returning from 'sysdb_search_object_by_str_attr'
9f2ebf
 #     return sysdb_search_object_by_str_attr(mem_ctx, domain, SYSDB_SID_FILTER,
9f2ebf
 #            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9f2ebf
 73. sssd-1.16.0/src/db/sysdb_ops.c:4209:11: note: Returning from 'sysdb_search_object_by_sid'
9f2ebf
 #     ret = sysdb_search_object_by_sid(tmp_ctx, domain, sid_str, NULL, &res;;
9f2ebf
 #           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9f2ebf
 76. sssd-1.16.0/src/db/sysdb_ops.c:4211:5: note: Taking false branch
9f2ebf
 #     if (ret == ENOENT) {
9f2ebf
 #     ^
9f2ebf
 79. sssd-1.16.0/src/db/sysdb_ops.c:4217:12: note: Taking false branch
9f2ebf
 #     } else if (ret != EOK) {
9f2ebf
 #            ^
9f2ebf
 82. sssd-1.16.0/src/db/sysdb_ops.c:4223:9: note: Dereference of undefined pointer value
9f2ebf
 #     if (res->count > 1) {
9f2ebf
 #         ^~~~~~~~~~
9f2ebf
 #  4221|       }
9f2ebf
 #  4222|
9f2ebf
 #  4223|->     if (res->count > 1) {
9f2ebf
 #  4224|           DEBUG(SSSDBG_FATAL_FAILURE, "getbysid call returned more than one " \
9f2ebf
 #  4225|                                        "result !?!\n");
9f2ebf
9f2ebf
Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
9f2ebf
9f2ebf
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
9f2ebf
(cherry picked from commit b739b3e767c053bb3a7e6651514896b30502d838)
9f2ebf
---
9f2ebf
 src/db/sysdb_ops.c | 2 +-
9f2ebf
 1 file changed, 1 insertion(+), 1 deletion(-)
9f2ebf
9f2ebf
diff --git a/src/db/sysdb_ops.c b/src/db/sysdb_ops.c
9f2ebf
index 2f8e36c6c9a2c2cefe4af5fb78957763304d989a..635c7db51f516e2217c93016409499e49289004c 100644
9f2ebf
--- a/src/db/sysdb_ops.c
9f2ebf
+++ b/src/db/sysdb_ops.c
9f2ebf
@@ -4874,7 +4874,7 @@ static errno_t sysdb_search_object_by_str_attr(TALLOC_CTX *mem_ctx,
9f2ebf
     }
9f2ebf
 
9f2ebf
     ret = sss_filter_sanitize(NULL, str, &sanitized);
9f2ebf
-    if (ret != EOK || sanitized == NULL) {
9f2ebf
+    if (ret != EOK) {
9f2ebf
         DEBUG(SSSDBG_OP_FAILURE, "sss_filter_sanitize failed.\n");
9f2ebf
         goto done;
9f2ebf
     }
9f2ebf
-- 
9f2ebf
2.13.6
9f2ebf