Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: liuye <liuye@kylinos.cn>
Cc: shuah@kernel.org, jeffxu@google.com, isaacmanjarres@google.com,
	lorenzo.stoakes@oracle.com, gthelen@google.com,
	sauravshah.31@gmail.com, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] selftests/memfd/memfd_test: Fix possible NULL pointer dereference
Date: Mon, 13 Jan 2025 20:13:51 -0800	[thread overview]
Message-ID: <20250113201351.3f48cc86f06a7dc01d497872@linux-foundation.org> (raw)
In-Reply-To: <20250114032115.58638-1-liuye@kylinos.cn>

On Tue, 14 Jan 2025 11:21:15 +0800 liuye <liuye@kylinos.cn> 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);
}


  reply	other threads:[~2025-01-14  4:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-14  3:21 [PATCH] selftests/memfd/memfd_test: Fix possible NULL pointer dereference liuye
2025-01-14  4:13 ` Andrew Morton [this message]
2025-01-14 11:10 ` Lorenzo Stoakes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250113201351.3f48cc86f06a7dc01d497872@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=gthelen@google.com \
    --cc=isaacmanjarres@google.com \
    --cc=jeffxu@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=liuye@kylinos.cn \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=sauravshah.31@gmail.com \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox