From 880f26f3eb4d5045dd8a44283022590efc074365 Mon Sep 17 00:00:00 2001 From: "Pedro F. Giffuni" Date: Wed, 24 May 2017 14:24:47 +0000 Subject: [PATCH] bhyvegc_resize: make use of reallocarray(3) for bounds-checking. Also add __FBSDID. Reviewed by: grehan This file lacks a license(!) so for this change the following declaration applies: To the greatest extent permitted by, but not in contravention of, applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and unconditionally waives, abandons, and surrenders all of Affirmer's Copyright and Related Rights and associated claims and causes of action, whether now known or unknown (including existing as well as future claims and causes of action). --- usr.sbin/bhyve/bhyvegc.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/usr.sbin/bhyve/bhyvegc.c b/usr.sbin/bhyve/bhyvegc.c index 377b05b0878f..0987e39dbb6b 100644 --- a/usr.sbin/bhyve/bhyvegc.c +++ b/usr.sbin/bhyve/bhyvegc.c @@ -1,4 +1,5 @@ #include +__FBSDID("$FreeBSD$"); #include @@ -56,9 +57,11 @@ bhyvegc_resize(struct bhyvegc *gc, int width, int height) gc_image->width = width; gc_image->height = height; if (!gc->raw) { - gc_image->data = realloc(gc_image->data, - sizeof (uint32_t) * width * height); - memset(gc_image->data, 0, width * height * sizeof (uint32_t)); + gc_image->data = reallocarray(gc_image->data, width * height, + sizeof (uint32_t)); + if (gc_image->data != NULL) + memset(gc_image->data, 0, width * height * + sizeof (uint32_t)); } }