Proposing SELinux support in strace

Dmitry V. Levin ldv at altlinux.org
Tue Mar 16 01:30:26 UTC 2021


On Mon, Mar 15, 2021 at 06:09:34PM +0100, Renaud Métrich wrote:
[...]
> diff --git a/tests/linkat--secontext.c b/tests/linkat--secontext.c
> index f2fd003d7..4818d676b 100644
> --- a/tests/linkat--secontext.c
> +++ b/tests/linkat--secontext.c
> @@ -20,6 +20,7 @@
>  # include <fcntl.h>
>  # include <stdio.h>
>  # include <unistd.h>
> +# include <xmalloc.h>
>  
>  /* for getcwd()/opendir() */
>  # include <limits.h>
> @@ -97,9 +98,7 @@ main(void)
>  		perror_msg_and_fail("dirfd");
>  
>  	static const char sample_2_dir[] = "new";
> -	char *new_sample_2 = malloc(strlen(sample_2_dir) + 1 + strlen(sample_2) + 1);
> -	if (new_sample_2 == NULL)
> -		perror_msg_and_fail("malloc");
> +	char *new_sample_2 = xmalloc(strlen(sample_2_dir) + 1 + strlen(sample_2) + 1);
>  	sprintf(new_sample_2, "%s/%s", sample_2_dir, sample_2);

I've added xasprintf to xmalloc, now you can write this as simple as

	char *new_sample_2 = xasprintf("%s/%s", sample_2_dir, sample_2);

-- 
ldv


More information about the Strace-devel mailing list