Skip to content

Commit 16b138d

Browse files
committed
Check illegal parameter.
1 parent a46773b commit 16b138d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/libipc/shm.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "libipc/shm.h"
66

77
#include "libipc/utility/pimpl.h"
8+
#include "libipc/utility/log.h"
89
#include "libipc/memory/resource.h"
910

1011
namespace ipc {
@@ -68,8 +69,17 @@ void handle::sub_ref() noexcept {
6869
}
6970

7071
bool handle::acquire(char const * name, std::size_t size, unsigned mode) {
72+
if (name == nullptr || name[0] == '\0') {
73+
ipc::error("fail acquire: name is empty\n");
74+
return false;
75+
}
76+
if (size == 0) {
77+
ipc::error("fail acquire: size is 0\n");
78+
return false;
79+
}
7180
release();
72-
impl(p_)->id_ = shm::acquire((impl(p_)->n_ = name).c_str(), size, mode);
81+
impl(p_)->n_ = name;
82+
impl(p_)->id_ = shm::acquire(name, size, mode);
7383
impl(p_)->m_ = shm::get_mem(impl(p_)->id_, &(impl(p_)->s_));
7484
return valid();
7585
}

0 commit comments

Comments
 (0)