* _init_caps() lists more than three capabilities.
* A 64-bit hexadecimal domain ID has at most 16 digits, not 17.  Size
  the buffer accordingly and drop a redundant domain_id check in
  audit_match_record().

Assisted-by: LLM
Signed-off-by: Günther Noack <[email protected]>
---
 tools/testing/selftests/landlock/audit.h  | 7 +++----
 tools/testing/selftests/landlock/common.h | 2 +-
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/tools/testing/selftests/landlock/audit.h 
b/tools/testing/selftests/landlock/audit.h
index 173dcd1088db..d23bb2ad3a30 100644
--- a/tools/testing/selftests/landlock/audit.h
+++ b/tools/testing/selftests/landlock/audit.h
@@ -274,15 +274,14 @@ static int audit_match_record(int audit_fd, const __u16 
type,
                *domain_id = 0;
                if (matches[1].rm_so != -1) {
                        int match_len = matches[1].rm_eo - matches[1].rm_so;
-                       /* The maximal characters of a 2^64 hexadecimal number 
is 17. */
-                       char dom_id[18];
+                       /* A 64-bit hexadecimal number has at most 16 digits. */
+                       char dom_id[17];
 
                        if (match_len > 0 && match_len < sizeof(dom_id)) {
                                memcpy(dom_id, msg.data + matches[1].rm_so,
                                       match_len);
                                dom_id[match_len] = '\0';
-                               if (domain_id)
-                                       *domain_id = strtoull(dom_id, NULL, 16);
+                               *domain_id = strtoull(dom_id, NULL, 16);
                        }
                }
        }
diff --git a/tools/testing/selftests/landlock/common.h 
b/tools/testing/selftests/landlock/common.h
index ae6a0eb8e343..f0e8d3a498b3 100644
--- a/tools/testing/selftests/landlock/common.h
+++ b/tools/testing/selftests/landlock/common.h
@@ -34,7 +34,7 @@ static const char bin_wait_pipe_sandbox[] = 
"./wait-pipe-sandbox";
 static void _init_caps(struct __test_metadata *const _metadata, bool drop_all)
 {
        cap_t cap_p;
-       /* Only these three capabilities are useful for the tests. */
+       /* Only these capabilities are useful for the tests. */
        const cap_value_t caps[] = {
                /* clang-format off */
                CAP_AUDIT_CONTROL,
-- 
2.56.0


Reply via email to