From 3a1b717b0e18ea18f0981079bbfcea5b797778ab Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Sun, 23 Sep 2018 09:57:28 +0200 Subject: [PATCH] Make sure multiplication result won't overflow integer type Make sure that multiplication result won't overflow int type before it is converted to size_t (which is unsigned int or unsigned long according to GNU C library documentation) Signed-off-by: Sebastien GODARD --- sa_conv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sa_conv.c b/sa_conv.c index a9eb91f..f257991 100644 --- a/sa_conv.c +++ b/sa_conv.c @@ -686,14 +686,14 @@ void upgrade_stats_queue(struct activity *act[], int p, unsigned int magic, * disk. *************************************************************************** */ -int upgrade_stats_serial(struct activity *act[], int p, int st_size, int endian_mismatch) +int upgrade_stats_serial(struct activity *act[], int p, size_t st_size, int endian_mismatch) { int i; unsigned int line; struct stats_serial *ssc; /* Copy TTY stats to target structure */ - memcpy(act[p]->buf[1], act[p]->buf[0], act[p]->nr_ini * st_size); + memcpy(act[p]->buf[1], act[p]->buf[0], (size_t) act[p]->nr_ini * st_size); for (i = 0; i < act[p]->nr_ini; i++) { ssc = (struct stats_serial *) ((char *) act[p]->buf[1] + i * act[p]->fsize); -- 2.40.0