[CRIU] [PATCHv2 2/2] zdtm/cgroup_ifpriomap: Fix Coverity warning

Dmitry Safonov 0x7f454c46 at gmail.com
Sun Feb 11 17:00:52 MSK 2018


*** CID 185302:  Null pointer dereferences  (NULL_RETURNS)
/test/zdtm/static/cgroup_ifpriomap.c: 107 in read_one_priomap()
>>>     Dereferencing a pointer that might be null "out->ifname" when calling "strncpy".

There is also a warning about using rand(), but..
Not sure that we need to entangle everything just for pleasing Coverity:
>>>     CID 185301:  Security best practices violations  (DC.WEAK_CRYPTO)
>>>     "rand" should not be used for security related applications, as linear congruential algorithms are too easy to break.
Leaving that as-is and marking in Coverity as WONTFIX.

Signed-off-by: Dmitry Safonov <0x7f454c46 at gmail.com>
---
 test/zdtm/static/cgroup_ifpriomap.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/test/zdtm/static/cgroup_ifpriomap.c b/test/zdtm/static/cgroup_ifpriomap.c
index ac186eaf05fd..f043b365b64f 100644
--- a/test/zdtm/static/cgroup_ifpriomap.c
+++ b/test/zdtm/static/cgroup_ifpriomap.c
@@ -104,6 +104,11 @@ static int read_one_priomap(char *prop_line, struct ifpriomap_t *out)
 	len = space - prop_line;
 
 	out->ifname = malloc(len + 1);
+	if (!out->ifname) {
+		pr_perror("malloc() failed\n");
+		return -1;
+	}
+
 	strncpy(out->ifname, prop_line, len);
 	out->ifname[len] = '\0'; /* poor man's strlcpy() */
 	out->prio = (uint32_t)strtol(space + 1, NULL, 10);
-- 
2.15.1



More information about the CRIU mailing list