audit_init_filter_exe() does not free the buffer returned by realpath(3)
when the path is too long.

Assisted-by: LLM
Signed-off-by: Günther Noack <[email protected]>
---
 tools/testing/selftests/landlock/audit.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/landlock/audit.h 
b/tools/testing/selftests/landlock/audit.h
index d428ce802f49..1e533b4e26db 100644
--- a/tools/testing/selftests/landlock/audit.h
+++ b/tools/testing/selftests/landlock/audit.h
@@ -507,8 +507,10 @@ static int audit_init_filter_exe(struct audit_filter 
*filter, const char *path)
 
        /* No need for the terminating NULL byte. */
        filter->exe_len = strlen(absolute_path);
-       if (filter->exe_len > sizeof(filter->exe))
+       if (filter->exe_len > sizeof(filter->exe)) {
+               free(absolute_path);
                return -E2BIG;
+       }
 
        memcpy(filter->exe, absolute_path, filter->exe_len);
        free(absolute_path);
-- 
2.56.0


Reply via email to