From 16b138d6af80fcab397c415ba3dd2bbfd8c36980 Mon Sep 17 00:00:00 2001 From: mutouyun Date: Sun, 24 Sep 2023 14:25:46 +0800 Subject: [PATCH] Check illegal parameter. --- src/libipc/shm.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/libipc/shm.cpp b/src/libipc/shm.cpp index 92f96ef..c8763a8 100755 --- a/src/libipc/shm.cpp +++ b/src/libipc/shm.cpp @@ -5,6 +5,7 @@ #include "libipc/shm.h" #include "libipc/utility/pimpl.h" +#include "libipc/utility/log.h" #include "libipc/memory/resource.h" namespace ipc { @@ -68,8 +69,17 @@ void handle::sub_ref() noexcept { } bool handle::acquire(char const * name, std::size_t size, unsigned mode) { + if (name == nullptr || name[0] == '\0') { + ipc::error("fail acquire: name is empty\n"); + return false; + } + if (size == 0) { + ipc::error("fail acquire: size is 0\n"); + return false; + } release(); - impl(p_)->id_ = shm::acquire((impl(p_)->n_ = name).c_str(), size, mode); + impl(p_)->n_ = name; + impl(p_)->id_ = shm::acquire(name, size, mode); impl(p_)->m_ = shm::get_mem(impl(p_)->id_, &(impl(p_)->s_)); return valid(); }