[Devel] zdtm: fix package memory allocation in autofs.c

Submitted by Stanislav Kinsburskiy on Aug. 31, 2017, 9:10 a.m.

Details

Message ID 20170831091037.249731.55500.stgit@skinsbursky-vz7.qa.sw.ru
State New
Series "zdtm: fix package memory allocation in autofs.c"
Headers show

Commit Message

Stanislav Kinsburskiy Aug. 31, 2017, 9:10 a.m.
Plus some cleanup.

https://jira.sw.ru/browse/PSBM-71078

Signed-off-by: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
---
 test/zdtm/static/autofs.c |   18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

Patch hide | download patch | download mbox

diff --git a/test/zdtm/static/autofs.c b/test/zdtm/static/autofs.c
index 8d917ee..882289f 100644
--- a/test/zdtm/static/autofs.c
+++ b/test/zdtm/static/autofs.c
@@ -460,10 +460,10 @@  static int automountd_loop(int pipe, const char *mountpoint, struct autofs_param
 {
 	union autofs_v5_packet_union *packet;
 	ssize_t bytes;
-	size_t psize = sizeof(*packet) * 2;
+	size_t psize = sizeof(*packet);
 	int err = 0;
 
-	packet = malloc(psize);
+	packet = malloc(psize * 2);
 	if (!packet) {
 		pr_err("failed to allocate autofs packet\n");
 		return -ENOMEM;
@@ -473,7 +473,7 @@  static int automountd_loop(int pipe, const char *mountpoint, struct autofs_param
 	siginterrupt(SIGUSR2, 1);
 
 	while (!stop && !err) {
-		memset(packet, 0, sizeof(*packet));
+		memset(packet, 0, psize * 2);
 
 		bytes = read(pipe, packet, psize);
 		if (bytes < 0) {
@@ -483,12 +483,12 @@  static int automountd_loop(int pipe, const char *mountpoint, struct autofs_param
 			}
 			continue;
 		}
-		if (bytes > psize) {
-			pr_err("read more that expected: %zd > %zd\n", bytes, psize);
-			return -EINVAL;
-		}
-		if (bytes != sizeof(*packet)) {
-			pr_err("read less than expected: %zd\n", bytes);
+		if (bytes != psize) {
+			pr_err("read %s that expected: %zd %s %zd\n",
+					(bytes > psize) ? "more" : "less",
+					bytes,
+					(bytes > psize) ? ">" : "<",
+					psize);
 			return -EINVAL;
 		}
 		err = automountd_serve(mountpoint, param, packet);

Comments

Andrey Vagin Sept. 9, 2017, 12:01 a.m.
On Thu, Aug 31, 2017 at 12:10:40PM +0300, Stanislav Kinsburskiy wrote:
> Plus some cleanup.

Do we need this patch for the upstream criu? Could you send it to
the criu mailing list?

> 
> https://jira.sw.ru/browse/PSBM-71078
> 
> Signed-off-by: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
> ---
>  test/zdtm/static/autofs.c |   18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/test/zdtm/static/autofs.c b/test/zdtm/static/autofs.c
> index 8d917ee..882289f 100644
> --- a/test/zdtm/static/autofs.c
> +++ b/test/zdtm/static/autofs.c
> @@ -460,10 +460,10 @@ static int automountd_loop(int pipe, const char *mountpoint, struct autofs_param
>  {
>  	union autofs_v5_packet_union *packet;
>  	ssize_t bytes;
> -	size_t psize = sizeof(*packet) * 2;
> +	size_t psize = sizeof(*packet);
>  	int err = 0;
>  
> -	packet = malloc(psize);
> +	packet = malloc(psize * 2);
>  	if (!packet) {
>  		pr_err("failed to allocate autofs packet\n");
>  		return -ENOMEM;
> @@ -473,7 +473,7 @@ static int automountd_loop(int pipe, const char *mountpoint, struct autofs_param
>  	siginterrupt(SIGUSR2, 1);
>  
>  	while (!stop && !err) {
> -		memset(packet, 0, sizeof(*packet));
> +		memset(packet, 0, psize * 2);
>  
>  		bytes = read(pipe, packet, psize);
>  		if (bytes < 0) {
> @@ -483,12 +483,12 @@ static int automountd_loop(int pipe, const char *mountpoint, struct autofs_param
>  			}
>  			continue;
>  		}
> -		if (bytes > psize) {
> -			pr_err("read more that expected: %zd > %zd\n", bytes, psize);
> -			return -EINVAL;
> -		}
> -		if (bytes != sizeof(*packet)) {
> -			pr_err("read less than expected: %zd\n", bytes);
> +		if (bytes != psize) {
> +			pr_err("read %s that expected: %zd %s %zd\n",
> +					(bytes > psize) ? "more" : "less",
> +					bytes,
> +					(bytes > psize) ? ">" : "<",
> +					psize);
>  			return -EINVAL;
>  		}
>  		err = automountd_serve(mountpoint, param, packet);
> 
> _______________________________________________
> Devel mailing list
> Devel@openvz.org
> https://lists.openvz.org/mailman/listinfo/devel
Stanislav Kinsburskiy Sept. 12, 2017, 8:55 a.m.
No, we don't.
But this one could be applied: "tests: do not try to read more than packet in AutoFS test"

09.09.2017 02:01, Andrei Vagin пишет:
> On Thu, Aug 31, 2017 at 12:10:40PM +0300, Stanislav Kinsburskiy wrote:
>> Plus some cleanup.
> 
> Do we need this patch for the upstream criu? Could you send it to
> the criu mailing list?
> 
>>
>> https://jira.sw.ru/browse/PSBM-71078
>>
>> Signed-off-by: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
>> ---
>>  test/zdtm/static/autofs.c |   18 +++++++++---------
>>  1 file changed, 9 insertions(+), 9 deletions(-)
>>
>> diff --git a/test/zdtm/static/autofs.c b/test/zdtm/static/autofs.c
>> index 8d917ee..882289f 100644
>> --- a/test/zdtm/static/autofs.c
>> +++ b/test/zdtm/static/autofs.c
>> @@ -460,10 +460,10 @@ static int automountd_loop(int pipe, const char *mountpoint, struct autofs_param
>>  {
>>  	union autofs_v5_packet_union *packet;
>>  	ssize_t bytes;
>> -	size_t psize = sizeof(*packet) * 2;
>> +	size_t psize = sizeof(*packet);
>>  	int err = 0;
>>  
>> -	packet = malloc(psize);
>> +	packet = malloc(psize * 2);
>>  	if (!packet) {
>>  		pr_err("failed to allocate autofs packet\n");
>>  		return -ENOMEM;
>> @@ -473,7 +473,7 @@ static int automountd_loop(int pipe, const char *mountpoint, struct autofs_param
>>  	siginterrupt(SIGUSR2, 1);
>>  
>>  	while (!stop && !err) {
>> -		memset(packet, 0, sizeof(*packet));
>> +		memset(packet, 0, psize * 2);
>>  
>>  		bytes = read(pipe, packet, psize);
>>  		if (bytes < 0) {
>> @@ -483,12 +483,12 @@ static int automountd_loop(int pipe, const char *mountpoint, struct autofs_param
>>  			}
>>  			continue;
>>  		}
>> -		if (bytes > psize) {
>> -			pr_err("read more that expected: %zd > %zd\n", bytes, psize);
>> -			return -EINVAL;
>> -		}
>> -		if (bytes != sizeof(*packet)) {
>> -			pr_err("read less than expected: %zd\n", bytes);
>> +		if (bytes != psize) {
>> +			pr_err("read %s that expected: %zd %s %zd\n",
>> +					(bytes > psize) ? "more" : "less",
>> +					bytes,
>> +					(bytes > psize) ? ">" : "<",
>> +					psize);
>>  			return -EINVAL;
>>  		}
>>  		err = automountd_serve(mountpoint, param, packet);
>>
>> _______________________________________________
>> Devel mailing list
>> Devel@openvz.org
>> https://lists.openvz.org/mailman/listinfo/devel