lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <20240830175902.2cbdb98ed746001896f57fe5@linux-foundation.org>
Date: Fri, 30 Aug 2024 17:59:02 -0700
From: Andrew Morton <akpm@...ux-foundation.org>
To: Zhu Jun <zhujun2@...s.chinamobile.com>
Cc: linux-mm@...ck.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2] tools/mm: Use calloc and check the memory allocation
 failure

On Thu, 29 Aug 2024 02:21:44 -0700 Zhu Jun <zhujun2@...s.chinamobile.com> wrote:

> Replace malloc with calloc and add null pointer check
> in case of allocation failure.
> 
> ...
>
> --- a/tools/mm/page_owner_sort.c
> +++ b/tools/mm/page_owner_sort.c
> @@ -368,9 +368,10 @@ static __u64 get_ts_nsec(char *buf)
>  
>  static char *get_comm(char *buf)
>  {
> -	char *comm_str = malloc(TASK_COMM_LEN);
> +	char *comm_str = calloc(TASK_COMM_LEN, sizeof(char));
>  
> -	memset(comm_str, 0, TASK_COMM_LEN);
> +	if (!comm_str)
> +		return NULL;

It seems rather pointless doing this when the caller aren't coded to
handle the NULL return.

And really, for these little userspace tools it's OK for us to just
assume that malloc() alway succeeds, isn't it?


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ