All of lore.kernel.org
 help / color / mirror / Atom feed
* [bug report] selftests/landlock: Add tests for audit flags and domain IDs
@ 2025-05-28  8:13 Dan Carpenter
  0 siblings, 0 replies; only message in thread
From: Dan Carpenter @ 2025-05-28  8:13 UTC (permalink / raw)
  To: Mickaël Salaün; +Cc: linux-kselftest

Hello Mickaël Salaün,

Commit 6a500b22971c ("selftests/landlock: Add tests for audit flags
and domain IDs") from Mar 20, 2025 (linux-next), leads to the
following Smatch static checker warning:

	tools/testing/selftests/landlock/audit.h:408 audit_init_filter_exe()
	warn: unsigned 'filter->exe_len' is never less than zero.

tools/testing/selftests/landlock/audit.h
    399 static int audit_init_filter_exe(struct audit_filter *filter, const char *path)
    400 {
    401         char *absolute_path = NULL;
    402 
    403         /* It is assume that there is not already filtering rules. */
    404         filter->record_type = AUDIT_EXE;
    405         if (!path) {
    406                 filter->exe_len = readlink("/proc/self/exe", filter->exe,
    407                                            sizeof(filter->exe) - 1);
--> 408                 if (filter->exe_len < 0)

size_t can't be negative.

    409                         return -errno;
    410 
    411                 return 0;
    412         }
    413 
    414         absolute_path = realpath(path, NULL);
    415         if (!absolute_path)
    416                 return -errno;
    417 
    418         /* No need for the terminating NULL byte. */
    419         filter->exe_len = strlen(absolute_path);
    420         if (filter->exe_len > sizeof(filter->exe))
    421                 return -E2BIG;
    422 
    423         memcpy(filter->exe, absolute_path, filter->exe_len);
    424         free(absolute_path);
    425         return 0;
    426 }

regards,
dan carpenter

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-05-28  8:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-28  8:13 [bug report] selftests/landlock: Add tests for audit flags and domain IDs Dan Carpenter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.