[PATCH 1/1] samples/seccomp: fix error return code in handle_req()

From: Zhen Lei
Date: Sat May 08 2021 - 00:01:23 EST


Unlike branch "if (lseek(mem, req->data.args[0], SEEK_SET) < 0)" above,
'ret' is overwritten by the previous 'ret = read(...)' statement.
Therefore, 'ret' needs to be explicitly assigned to -1 here. Otherwise,
0 is incorrectly returned.

Reported-by: Hulk Robot <hulkci@xxxxxxxxxx>
Signed-off-by: Zhen Lei <thunder.leizhen@xxxxxxxxxx>
---
samples/seccomp/user-trap.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/samples/seccomp/user-trap.c b/samples/seccomp/user-trap.c
index 20291ec6489f..c1d4ca0284ba 100644
--- a/samples/seccomp/user-trap.c
+++ b/samples/seccomp/user-trap.c
@@ -164,6 +164,7 @@ static int handle_req(struct seccomp_notif *req,
}

if (lseek(mem, req->data.args[1], SEEK_SET) < 0) {
+ ret = -1;
perror("seek");
goto out;
}
--
2.25.1