diff options
author | David Robillard <d@drobilla.net> | 2024-10-06 18:25:33 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2024-10-11 19:58:12 -0400 |
commit | f447448aa3c6c944a27c29793b92f4d7fb5df432 (patch) | |
tree | 56ff2c07b5b58d15a672e9daa38ec10d2b5b3db0 /src/server | |
parent | ae5e9980aabba34a5e7fbf101b55200b8b127573 (diff) | |
download | ingen-f447448aa3c6c944a27c29793b92f4d7fb5df432.tar.gz ingen-f447448aa3c6c944a27c29793b92f4d7fb5df432.tar.bz2 ingen-f447448aa3c6c944a27c29793b92f4d7fb5df432.zip |
Handle realloc failure and avoid potential null pointer arithmetic
Diffstat (limited to 'src/server')
-rw-r--r-- | src/server/.clang-tidy | 1 | ||||
-rw-r--r-- | src/server/Buffer.cpp | 7 | ||||
-rw-r--r-- | src/server/ingen_lv2.cpp | 8 |
3 files changed, 13 insertions, 3 deletions
diff --git a/src/server/.clang-tidy b/src/server/.clang-tidy index 6990b1fe..a580cc7e 100644 --- a/src/server/.clang-tidy +++ b/src/server/.clang-tidy @@ -6,7 +6,6 @@ Checks: > -bugprone-branch-clone, -bugprone-parent-virtual-call, -bugprone-reserved-identifier, - -bugprone-suspicious-realloc-usage, -bugprone-suspicious-string-compare, -cert-dcl37-c, -cert-dcl51-cpp, diff --git a/src/server/Buffer.cpp b/src/server/Buffer.cpp index ea3205fb..68b75931 100644 --- a/src/server/Buffer.cpp +++ b/src/server/Buffer.cpp @@ -172,7 +172,12 @@ void Buffer::resize(uint32_t capacity) { if (!_external) { - _buf = realloc(_buf, capacity); + void* const new_buf = realloc(_buf, capacity); + if (!new_buf) { + throw std::bad_alloc{}; + } + + _buf = new_buf; _capacity = capacity; clear(); } else { diff --git a/src/server/ingen_lv2.cpp b/src/server/ingen_lv2.cpp index 930f350d..76bdcb54 100644 --- a/src/server/ingen_lv2.cpp +++ b/src/server/ingen_lv2.cpp @@ -318,7 +318,13 @@ public: break; } - buf = realloc(buf, sizeof(LV2_Atom) + atom.size); + void* const new_buf = realloc(buf, sizeof(LV2_Atom) + atom.size); + if (!new_buf) { + _engine.log().rt_error("Failed to allocate for from-UI ring\n"); + break; + } + + buf = new_buf; memcpy(buf, &atom, sizeof(LV2_Atom)); if (!_from_ui.read(atom.size, |