From 308c68c07d6f52a3d5f782a8fe88e1873a766977 Mon Sep 17 00:00:00 2001 From: Dirk Thomas Date: Wed, 1 May 2019 12:52:33 -0700 Subject: [PATCH] check n in resize function Signed-off-by: Dirk Thomas --- rosidl_generator_c/src/u16string_functions.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rosidl_generator_c/src/u16string_functions.c b/rosidl_generator_c/src/u16string_functions.c index ff58c1b90..cc0940b49 100644 --- a/rosidl_generator_c/src/u16string_functions.c +++ b/rosidl_generator_c/src/u16string_functions.c @@ -134,6 +134,10 @@ rosidl_generator_c__U16String__resize( if (!str) { return false; } + // check valid range of n before allocating n + 1 characters + if (n > SIZE_MAX / sizeof(uint16_t) - 1) { + return false; + } uint16_t * data = realloc(str->data, (n + 1) * sizeof(uint16_t)); if (!data) { return false;