Skip to content

Commit

Permalink
tools/hv: Add memory allocation check in hv_fcopy_start
Browse files Browse the repository at this point in the history
[ Upstream commit 94e86b1 ]

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]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
Zhu Jun authored and gregkh committed Oct 10, 2024
1 parent f6d50dd commit bf050cc
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tools/hv/hv_fcopy_uio_daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit bf050cc

Please sign in to comment.