fix: Avoided dereferencing NULL pointer (#34836)

issue : https://github.com/milvus-io/milvus/issues/34835

Signed-off-by: Ald392 <imagesai32@gmail.com>
This commit is contained in:
Aldrin 2024-07-27 14:57:52 +05:30 committed by GitHub
parent 804ec24c02
commit 9463eeef2b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 11 additions and 0 deletions

View File

@ -10,7 +10,9 @@
// or implied. See the License for the specific language governing permissions and limitations under the License
#include <string.h>
#include "common/EasyAssert.h"
#include "config/ConfigKnowhere.h"
#include "fmt/core.h"
#include "indexbuilder/init_c.h"
void
@ -23,6 +25,7 @@ char*
IndexBuilderSetSimdType(const char* value) {
auto real_type = milvus::config::KnowhereSetSimdType(value);
char* ret = reinterpret_cast<char*>(malloc(real_type.length() + 1));
AssertInfo(ret != nullptr, "memmory allocation for ret failed!");
memcpy(ret, real_type.c_str(), real_type.length());
ret[real_type.length()] = 0;
return ret;

View File

@ -14,6 +14,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "common/EasyAssert.h"
#include "fmt/core.h"
#include "log/Log.h"
/*
@ -105,6 +107,7 @@ get_thread_starttime() {
int64_t val = 0;
char comm[16], state;
FILE* thread_stat = fopen(filename, "r");
AssertInfo(thread_stat != nullptr, "opening file:{} failed!", filename);
auto ret = fscanf(
thread_stat, "%lld %s %s ", (long long*)&val, comm, &state); // NOLINT

View File

@ -11,6 +11,8 @@
#include <string>
#include "common/EasyAssert.h"
#include "fmt/core.h"
#include "knowhere/prometheus_client.h"
#include "segcore/metrics_c.h"
@ -19,6 +21,7 @@ GetKnowhereMetrics() {
auto str = knowhere::prometheusClient->GetMetrics();
auto len = str.length();
char* res = (char*)malloc(len + 1);
AssertInfo(res != nullptr, "memmory allocation for res failed!");
memcpy(res, str.data(), len);
res[len] = '\0';
return res;

View File

@ -10,6 +10,7 @@
// or implied. See the License for the specific language governing permissions and limitations under the License
#include "config/ConfigKnowhere.h"
#include "fmt/core.h"
#include "log/Log.h"
#include "segcore/SegcoreConfig.h"
#include "segcore/segcore_init_c.h"
@ -74,6 +75,7 @@ SegcoreSetSimdType(const char* value) {
LOG_DEBUG("set config simd_type: {}", value);
auto real_type = milvus::config::KnowhereSetSimdType(value);
char* ret = reinterpret_cast<char*>(malloc(real_type.length() + 1));
AssertInfo(ret != nullptr, "memmory allocation for ret failed!");
memcpy(ret, real_type.c_str(), real_type.length());
ret[real_type.length()] = 0;
return ret;