Commit cc0fdc63c7b4c75f721f7cf5e8ca65f6bc6459ce

Thomas de Grivel 2023-07-15T15:08:07

fix buffer overflow

1
2
3
4
5
6
7
8
9
10
11
12
13
14
diff --git a/libc3/buf_parse.c b/libc3/buf_parse.c
index 0a37926..137441e 100644
--- a/libc3/buf_parse.c
+++ b/libc3/buf_parse.c
@@ -302,7 +302,8 @@ sw buf_parse_array_dimensions_rec (s_buf *buf, s_array *dest,
   result += r;
   if (! tmp.dimensions[dimension].count) {
     tmp.dimensions[dimension].count = address[dimension];
-    tmp.dimensions[dimension].item_size = tmp.dimensions[dimension + 1].count * tmp.dimensions[dimension + 1].item_size;
+    if (dimension < tmp.dimension - 1)
+      tmp.dimensions[dimension].item_size = tmp.dimensions[dimension + 1].count * tmp.dimensions[dimension + 1].item_size;
   }
   else if (tmp.dimensions[dimension].count != address[dimension]) {
     assert(! "buf_parse_array_dimensions_rec: dimension mismatch");