summarylogtreecommitdiffstats
path: root/0004-lib-asn1_utils-fix-out-of-bounds-access-on-zero-size.patch
blob: 7de6fdf0625bc33e2f4cc3f3ed7e4f13f5460c86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
From 0c9ba5b87ee246b772c9deb2993834f0b7fc088b Mon Sep 17 00:00:00 2001
From: Robert Falkenberg <robert.falkenberg@srs.io>
Date: Fri, 13 May 2022 16:47:52 +0200
Subject: [PATCH] lib,asn1_utils: fix out of bounds access on zero-sized array
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* fix error: ... offset 0 is out of the bounds [0, 0] [-Werror=array-bounds]
* fix note: destination object of size 0 allocated by ‘operator new []’
--> data_ = new T[cap_];
---
 lib/include/srsran/asn1/asn1_utils.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lib/include/srsran/asn1/asn1_utils.h b/lib/include/srsran/asn1/asn1_utils.h
index 87696d7b6..f1dcfcd74 100644
--- a/lib/include/srsran/asn1/asn1_utils.h
+++ b/lib/include/srsran/asn1/asn1_utils.h
@@ -193,8 +193,12 @@ public:
   {
     size_ = nof_items;
     cap_  = nof_items;
-    data_ = new T[cap_];
-    std::copy(ptr, ptr + size_, data_);
+    if (ptr != NULL) {
+      data_ = new T[cap_];
+      std::copy(ptr, ptr + size_, data_);
+    } else {
+      data_ = NULL;
+    }
   }
   ~dyn_array()
   {
-- 
2.36.1