]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
api.c: check the bytes read in cgroup_register_unchanged_process()
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Thu, 28 Jul 2022 19:34:33 +0000 (13:34 -0600)
committerTom Hromatka <tom.hromatka@oracle.com>
Thu, 28 Jul 2022 19:34:35 +0000 (13:34 -0600)
Fix ignoring the number of bytes read, warning reported by Coverity
tool:

CID 258288 (#1 of 1): Ignoring number of bytes read (CHECKED_RETURN).
check_return: read(int, void *, size_t) returns the number of bytes
read, but it is ignored.

In cgroup_register_unchanged_process(), the number of byte read/written
using read()/write() are ignored but coverity it warns about the read()
only, let's fix it.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 9d266da61515bb47b889a93229302e545da207fe)

src/api.c

index 4a451b497e2e61c349a9238d46aa62f9f018bb49..e2eba8c2af7ab69dae9a21d8e0bdb33d1f21ecb7 100644 (file)
--- a/src/api.c
+++ b/src/api.c
@@ -5391,6 +5391,7 @@ int cgroup_register_unchanged_process(pid_t pid, int flags)
        int ret = 1;
        char buff[sizeof(CGRULE_SUCCESS_STORE_PID)];
        struct sockaddr_un addr;
+       size_t ret_len;
 
        sk = socket(PF_UNIX, SOCK_STREAM, 0);
        if (sk < 0)
@@ -5413,7 +5414,8 @@ int cgroup_register_unchanged_process(pid_t pid, int flags)
        if (write(sk, &flags, sizeof(flags)) < 0)
                goto close;
 
-       if (read(sk, buff, sizeof(buff)) < 0)
+       ret_len = read(sk, buff, sizeof(buff));
+       if (ret_len != sizeof(buff))
                goto close;
 
        if (strncmp(buff, CGRULE_SUCCESS_STORE_PID, sizeof(buff)))