lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID:
 <SA1PR21MB13179B929747B9B88948DCA5BF902@SA1PR21MB1317.namprd21.prod.outlook.com>
Date: Sat, 31 Aug 2024 00:34:43 +0000
From: Dexuan Cui <decui@...rosoft.com>
To: Zhu Jun <zhujun2@...s.chinamobile.com>, KY Srinivasan <kys@...rosoft.com>
CC: Haiyang Zhang <haiyangz@...rosoft.com>, "wei.liu@...nel.org"
	<wei.liu@...nel.org>, "linux-hyperv@...r.kernel.org"
	<linux-hyperv@...r.kernel.org>, "linux-kernel@...r.kernel.org"
	<linux-kernel@...r.kernel.org>
Subject: RE: [PATCH v2] tools/hv: Add memory allocation check in
 hv_fcopy_start

> From: Zhu Jun <zhujun2@...s.chinamobile.com>
> Sent: Wednesday, August 28, 2024 7:45 PM
> @@ -296,6 +296,18 @@ 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) {
> +        free(file_name);
> +        syslog(LOG_ERR, "Can't allocate file_name memory!");
> +        exit(EXIT_FAILURE);
> +    }
> +
> +    if (!path_name) {
> +        free(path_name);
> +        syslog(LOG_ERR, "Can't allocate path_name memory!");
> +        exit(EXIT_FAILURE);
> +    }

If we're calling exit() just 2 lines later, it doesn't make a lot of sense
to call free().

How about this:

@@ -296,6 +296,12 @@ 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;
+       }

Note: free(NULL) is valid (refer to "man 3 free").

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ