linux-hyperv.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tools/hv: Add memory allocation check in hv_fcopy_start
@ 2024-08-28 10:00 Zhu Jun
  2024-08-28 10:18 ` Praveen Kumar
  0 siblings, 1 reply; 2+ messages in thread
From: Zhu Jun @ 2024-08-28 10:00 UTC (permalink / raw)
  To: kys; +Cc: haiyangz, wei.liu, decui, linux-hyperv, linux-kernel, zhujun2

Added checks for `file_name` and `path_name` memory allocation failures,
with error logging and process exit on failure.

Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com>
---
 tools/hv/hv_fcopy_uio_daemon.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/hv/hv_fcopy_uio_daemon.c b/tools/hv/hv_fcopy_uio_daemon.c
index 3ce316cc9f97..2efdf8d28e9c 100644
--- a/tools/hv/hv_fcopy_uio_daemon.c
+++ b/tools/hv/hv_fcopy_uio_daemon.c
@@ -295,6 +295,10 @@ static int hv_fcopy_start(struct hv_start_fcopy *smsg_in)
 
 	file_name = (char *)malloc(file_size * sizeof(char));
 	path_name = (char *)malloc(path_size * sizeof(char));
+	if (!file_name || !path_name) {
+		syslog(LOG_ERR, "Can't allocate memory!");
+		exit(EXIT_FAILURE);
+	}
 
 	wcstoutf8(file_name, (__u16 *)in_file_name, file_size);
 	wcstoutf8(path_name, (__u16 *)in_path_name, path_size);
-- 
2.17.1




^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] tools/hv: Add memory allocation check in hv_fcopy_start
  2024-08-28 10:00 [PATCH] tools/hv: Add memory allocation check in hv_fcopy_start Zhu Jun
@ 2024-08-28 10:18 ` Praveen Kumar
  0 siblings, 0 replies; 2+ messages in thread
From: Praveen Kumar @ 2024-08-28 10:18 UTC (permalink / raw)
  To: Zhu Jun, kys; +Cc: haiyangz, wei.liu, decui, linux-hyperv, linux-kernel

On 28/08/24 15:30, Zhu Jun wrote:
> Added checks for `file_name` and `path_name` memory allocation failures,
> with error logging and process exit on failure.
> 
> Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com>
> ---
>   tools/hv/hv_fcopy_uio_daemon.c | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/tools/hv/hv_fcopy_uio_daemon.c b/tools/hv/hv_fcopy_uio_daemon.c
> index 3ce316cc9f97..2efdf8d28e9c 100644
> --- a/tools/hv/hv_fcopy_uio_daemon.c
> +++ b/tools/hv/hv_fcopy_uio_daemon.c
> @@ -295,6 +295,10 @@ static int hv_fcopy_start(struct hv_start_fcopy *smsg_in)
>   
>   	file_name = (char *)malloc(file_size * sizeof(char));
>   	path_name = (char *)malloc(path_size * sizeof(char));
> +	if (!file_name || !path_name) {
> +		syslog(LOG_ERR, "Can't allocate memory!");

Probably, you may want to cleanup memory here in case either of one is 
successful allocation.

> +		exit(EXIT_FAILURE);
> +	}
>   
>   	wcstoutf8(file_name, (__u16 *)in_file_name, file_size);
>   	wcstoutf8(path_name, (__u16 *)in_path_name, path_size);


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-08-28 10:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-28 10:00 [PATCH] tools/hv: Add memory allocation check in hv_fcopy_start Zhu Jun
2024-08-28 10:18 ` Praveen Kumar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).