Re: [PATCH] selftests/memfd/memfd_test: Fix possible NULL pointer dereference

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 14 Jan 2025 11:21:15 +0800 liuye <liuye@xxxxxxxxxx> wrote:

>     If name is NULL, a NULL pointer may be accessed in printf.
> 
> ...
>
> --- a/tools/testing/selftests/memfd/memfd_test.c
> +++ b/tools/testing/selftests/memfd/memfd_test.c
> @@ -171,7 +171,7 @@ static void mfd_fail_new(const char *name, unsigned int flags)
>  	r = sys_memfd_create(name, flags);
>  	if (r >= 0) {
>  		printf("memfd_create(\"%s\", %u) succeeded, but failure expected\n",
> -		       name, flags);
> +		       name ? name : "NULL", flags);
>  		close(r);
>  		abort();

Well huh.  I though printf() would emit "(null)" in this situation, but
my super-sophisticated test case says "core dumped".

#include <stdio.h>
#include <stdlib.h>

int main()
{
	printf("%s\n", (char *)0);
	exit(0);
}





[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux