[LTP] [PATCH] genload: fix memory corruption in hogvm

Cyril Hrubis chrubis@suse.cz
Tue Jun 11 14:11:26 CEST 2024


Hi!
> Signed-off-by: Jiwei Sun <sunjw10@lenovo.com>
> ---
>  tools/genload/genload.c | 2 +-
>  tools/genload/stress.c  | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/genload/genload.c b/tools/genload/genload.c
> index 7f56d5272..9712e7828 100644
> --- a/tools/genload/genload.c
> +++ b/tools/genload/genload.c
> @@ -642,7 +642,7 @@ int hogvm(long long forks, long long chunks, long long bytes)
>  			usleep(backoff);
>  
>  			while (1) {
> -				ptr = (char **)malloc(chunks * 2);
> +				ptr = (char **)malloc(chunks * 2 * sizeof(char *));

Good catch, however shouldn't this be just chunks * sizeof(char*) ?

>  				for (j = 0; chunks == 0 || j < chunks; j++) {
>  					if ((ptr[j] =
>  					     (char *)malloc(bytes *
> diff --git a/tools/genload/stress.c b/tools/genload/stress.c
> index 7f56d5272..9712e7828 100644
> --- a/tools/genload/stress.c
> +++ b/tools/genload/stress.c
> @@ -642,7 +642,7 @@ int hogvm(long long forks, long long chunks, long long bytes)
>  			usleep(backoff);
>  
>  			while (1) {
> -				ptr = (char **)malloc(chunks * 2);
> +				ptr = (char **)malloc(chunks * 2 * sizeof(char *));

Here as well.

>  				for (j = 0; chunks == 0 || j < chunks; j++) {
>  					if ((ptr[j] =
>  					     (char *)malloc(bytes *
> -- 
> 2.27.0
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list