diff options
author | Zhu Jun | 2024-09-06 02:13:33 -0700 |
---|---|---|
committer | Wei Liu | 2024-09-09 01:09:27 +0000 |
commit | 94e86b174d103d941b4afc4f016af8af9e5352fa (patch) | |
tree | 6e6df7094e3c8901eaf59a32abb880e4c9bd04aa | |
parent | 0b5530861eec1cf3f240a6a4a0ceed58f67fbcc5 (diff) |
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 <zhujun2@cmss.chinamobile.com>
Reviewed-by: Dexuan Cui <decui@microsoft.com>
Tested-by: Saurabh Sengar <ssengar@linux.microsoft.com>
Link: https://lore.kernel.org/r/20240906091333.11419-1-zhujun2@cmss.chinamobile.com
Signed-off-by: Wei Liu <wei.liu@kernel.org>
Message-ID: <20240906091333.11419-1-zhujun2@cmss.chinamobile.com>
-rw-r--r-- | tools/hv/hv_fcopy_uio_daemon.c | 7 |
1 files changed, 7 insertions, 0 deletions
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); |