linux-hyperv.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] tools/hv: Add memory allocation check in hv_fcopy_start
@ 2024-09-06  9:13 Zhu Jun
  2024-09-07  0:53 ` Dexuan Cui
  2024-09-09  1:09 ` Wei Liu
  0 siblings, 2 replies; 4+ messages in thread
From: Zhu Jun @ 2024-09-06  9:13 UTC (permalink / raw)
  To: decui; +Cc: kys, haiyangz, wei.liu, linux-hyperv, linux-kernel, zhujun2

Added error handling for memory allocation failures
of file_name and path_name.

Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com>
---
v1->v2:
    Add cleanup memory
v2->v3:
	If we're calling exit() just 2 lines later, it doesn't make a lot of sense
	to call free().
	free(NULL) is valid (refer to "man 3 free").

 tools/hv/hv_fcopy_uio_daemon.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/tools/hv/hv_fcopy_uio_daemon.c b/tools/hv/hv_fcopy_uio_daemon.c
index 3ce316cc9f97..7a00f3066a98 100644
--- a/tools/hv/hv_fcopy_uio_daemon.c
+++ b/tools/hv/hv_fcopy_uio_daemon.c
@@ -296,6 +296,13 @@ 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) {
+		free(file_name);
+		free(path_name);
+		syslog(LOG_ERR, "Can't allocate memory for file name and/or path name");
+		return HV_E_FAIL;
+	}
+
 	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] 4+ messages in thread

* RE: [PATCH v3] tools/hv: Add memory allocation check in hv_fcopy_start
  2024-09-06  9:13 [PATCH v3] tools/hv: Add memory allocation check in hv_fcopy_start Zhu Jun
@ 2024-09-07  0:53 ` Dexuan Cui
  2024-09-07  4:33   ` Saurabh Singh Sengar
  2024-09-09  1:09 ` Wei Liu
  1 sibling, 1 reply; 4+ messages in thread
From: Dexuan Cui @ 2024-09-07  0:53 UTC (permalink / raw)
  To: Zhu Jun
  Cc: KY Srinivasan, Haiyang Zhang, wei.liu@kernel.org,
	linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org

> From: Zhu Jun <zhujun2@cmss.chinamobile.com>
> Sent: Friday, September 6, 2024 2:14 AM

Reviewed-by: Dexuan Cui <decui@microsoft.com>

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

* Re: [PATCH v3] tools/hv: Add memory allocation check in hv_fcopy_start
  2024-09-07  0:53 ` Dexuan Cui
@ 2024-09-07  4:33   ` Saurabh Singh Sengar
  0 siblings, 0 replies; 4+ messages in thread
From: Saurabh Singh Sengar @ 2024-09-07  4:33 UTC (permalink / raw)
  To: Dexuan Cui
  Cc: Zhu Jun, KY Srinivasan, Haiyang Zhang, wei.liu@kernel.org,
	linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org

On Sat, Sep 07, 2024 at 12:53:02AM +0000, Dexuan Cui wrote:
> > From: Zhu Jun <zhujun2@cmss.chinamobile.com>
> > Sent: Friday, September 6, 2024 2:14 AM
> 
> Reviewed-by: Dexuan Cui <decui@microsoft.com>

Tested-by: Saurabh Sengar <ssengar@linux.microsoft.com>

- Saurabh

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

* Re: [PATCH v3] tools/hv: Add memory allocation check in hv_fcopy_start
  2024-09-06  9:13 [PATCH v3] tools/hv: Add memory allocation check in hv_fcopy_start Zhu Jun
  2024-09-07  0:53 ` Dexuan Cui
@ 2024-09-09  1:09 ` Wei Liu
  1 sibling, 0 replies; 4+ messages in thread
From: Wei Liu @ 2024-09-09  1:09 UTC (permalink / raw)
  To: Zhu Jun; +Cc: decui, kys, haiyangz, wei.liu, linux-hyperv, linux-kernel

On Fri, Sep 06, 2024 at 02:13:33AM -0700, Zhu Jun wrote:
> Added error handling for memory allocation failures
> of file_name and path_name.
> 
> Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com>

Applied to hyperv-next, thanks.

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

end of thread, other threads:[~2024-09-09  1:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-06  9:13 [PATCH v3] tools/hv: Add memory allocation check in hv_fcopy_start Zhu Jun
2024-09-07  0:53 ` Dexuan Cui
2024-09-07  4:33   ` Saurabh Singh Sengar
2024-09-09  1:09 ` Wei Liu

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).