Skip to content

Commit 94e86b1

Browse files
Zhu Junliuw
authored andcommitted
tools/hv: Add memory allocation check in hv_fcopy_start
Added error handling for memory allocation failures of file_name and path_name. Signed-off-by: Zhu Jun <[email protected]> Reviewed-by: Dexuan Cui <[email protected]> Tested-by: Saurabh Sengar <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Wei Liu <[email protected]> Message-ID: <[email protected]>
1 parent 0b55308 commit 94e86b1

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

tools/hv/hv_fcopy_uio_daemon.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,13 @@ static int hv_fcopy_start(struct hv_start_fcopy *smsg_in)
296296
file_name = (char *)malloc(file_size * sizeof(char));
297297
path_name = (char *)malloc(path_size * sizeof(char));
298298

299+
if (!file_name || !path_name) {
300+
free(file_name);
301+
free(path_name);
302+
syslog(LOG_ERR, "Can't allocate memory for file name and/or path name");
303+
return HV_E_FAIL;
304+
}
305+
299306
wcstoutf8(file_name, (__u16 *)in_file_name, file_size);
300307
wcstoutf8(path_name, (__u16 *)in_path_name, path_size);
301308

0 commit comments

Comments
 (0)