Blame SOURCES/0059-NSS-Fix-covscan-warning.patch

9f2ebf
From 2fd201a6e8f263f30fb3aeb3d7f826a06321e58e Mon Sep 17 00:00:00 2001
9f2ebf
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@redhat.com>
9f2ebf
Date: Tue, 21 Nov 2017 16:12:24 +0100
9f2ebf
Subject: [PATCH 59/59] NSS: Fix covscan warning
9f2ebf
MIME-Version: 1.0
9f2ebf
Content-Type: text/plain; charset=UTF-8
9f2ebf
Content-Transfer-Encoding: 8bit
9f2ebf
9f2ebf
 Error: NULL_RETURNS (CWE-476): [#def1]
9f2ebf
 sssd-1.16.1/src/responder/nss/nss_protocol.c:162: returned_null: "memchr" returns null (checked 7 out of 8 times).
9f2ebf
 sssd-1.16.1/src/responder/nss/nsssrv_mmap_cache.c:557: example_checked: Example 1: "memchr(t_key, 0, strs_offset + strs_len - name_ptr)" has its value checked in "memchr(t_key, 0, strs_offset + strs_len - name_ptr) == NULL".
9f2ebf
 sssd-1.16.1/src/sss_client/idmap/sss_nss_idmap.c:171: example_assign: Example 2: Assigning: "p" = return value from "memchr(p, 0, buf_len - (p - buf))".
9f2ebf
 sssd-1.16.1/src/sss_client/idmap/sss_nss_idmap.c:172: example_checked: Example 2 (cont.): "p" has its value checked in "p == NULL".
9f2ebf
 sssd-1.16.1/src/sss_client/nss_mc_group.c:157: example_checked: Example 3: "memchr(rec_name, 0, 16UL + data->strs_len - data->name)" has its value checked in "memchr(rec_name, 0, 16UL + data->strs_len - data->name) == NULL".
9f2ebf
 sssd-1.16.1/src/sss_client/nss_mc_initgr.c:139: example_checked: Example 4: "memchr(rec_name, 0, 24UL + data->data_len - data->name)" has its value checked in "memchr(rec_name, 0, 24UL + data->data_len - data->name) == NULL".
9f2ebf
 sssd-1.16.1/src/sss_client/nss_mc_passwd.c:150: example_checked: Example 5: "memchr(rec_name, 0, 16UL + data->strs_len - data->name)" has its value checked in "memchr(rec_name, 0, 16UL + data->strs_len - data->name) == NULL".
9f2ebf
 sssd-1.16.1/src/responder/nss/nss_protocol.c:162: var_assigned: Assigning: "p" = null return value from "memchr".
9f2ebf
 sssd-1.16.1/src/responder/nss/nss_protocol.c:176: dereference: Incrementing a pointer which might be null: "p".
9f2ebf
 #  174|       }
9f2ebf
 #  175|
9f2ebf
 #  176|->     p++;
9f2ebf
 #  177|       if ((p - body) + sizeof(uint32_t) != blen) {
9f2ebf
 #  178|           DEBUG(SSSDBG_CRIT_FAILURE, "Body has unexpected size!\n");
9f2ebf
9f2ebf
Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
9f2ebf
9f2ebf
Reviewed-by: Lukáš Slebodník <lslebodn@redhat.com>
9f2ebf
Reviewed-by: Michal Židek <mzidek@redhat.com>
9f2ebf
(cherry picked from commit 1d88a0591ce8445ea3b6a88845a5997d61c915b4)
9f2ebf
---
9f2ebf
 src/responder/nss/nss_protocol.c | 7 +++++++
9f2ebf
 1 file changed, 7 insertions(+)
9f2ebf
9f2ebf
diff --git a/src/responder/nss/nss_protocol.c b/src/responder/nss/nss_protocol.c
9f2ebf
index 2655386498754c46fbb363bdd1f976f9ded6a434..13f6d1541b79bf5494e1560841f027bf98bef72b 100644
9f2ebf
--- a/src/responder/nss/nss_protocol.c
9f2ebf
+++ b/src/responder/nss/nss_protocol.c
9f2ebf
@@ -160,6 +160,13 @@ nss_protocol_parse_name_ex(struct cli_ctx *cli_ctx, const char **_rawname,
9f2ebf
     }
9f2ebf
 
9f2ebf
     p = memchr(body, '\0', blen);
9f2ebf
+    /* Although body for sure is null terminated, let's add this check here
9f2ebf
+     * so static analyzers are happier. */
9f2ebf
+    if (p == NULL) {
9f2ebf
+        DEBUG(SSSDBG_CRIT_FAILURE,
9f2ebf
+              "memchr() returned NULL, body is not null terminated!\n");
9f2ebf
+        return EINVAL;
9f2ebf
+    }
9f2ebf
 
9f2ebf
     /* If the body isn't valid UTF-8, fail */
9f2ebf
     if (!sss_utf8_check(body, (p - body))) {
9f2ebf
-- 
9f2ebf
2.14.3
9f2ebf