fix(libmsg): complete security audit round 2 - fix P0 race + harden input validation
- P0: fix _close_all_clients() race condition (CWE-362) - hold per-connection send_lock before close() to prevent messages being sent to wrong client after fd reuse - P2: add comprehensive input validation for all public APIs (timeout/port/workers/max_connections/batch_size etc. bounds checking) - P2: add UTF-8 payload validation (isValidUtf8) aligning with Python pymsg behavior, rejecting overlong encodings, surrogate pairs, truncated/invalid sequences - P2: document pmsg_recv(int) precondition and recommend deadline mode - add constructor validation for MsgClient/MsgServer/AsyncQueue/RpcClient/RpcServer - add add_route() validation for empty route name and null handler - update security audit report with round 2 findings and fixes (8 issues total, 100% fixed)
This commit is contained in:
1 parent
9256a8157b
commit
3c50a862d3
6 files changed
+351
-76
No files matched your search
@@ -80,10 +80,16 @@ public:
|
||||
|
||||
/** 注册路由处理函数。
|
||||
*
|
||||
* @param name 路由名(对应请求中的 _route 字段)
|
||||
* @param name 路由名(对应请求中的 _route 字段),不能为空
|
||||
* @param handler 处理函数,签名 json::value(const json::object& req)
|
||||
*/
|
||||
void add_route(const std::string& name, Handler handler) {
|
||||
if (name.empty()) {
|
||||
throw MsgException("route name cannot be empty");
|
||||
}
|
||||
if (!handler) {
|
||||
throw MsgException("route handler cannot be null");
|
||||
}
|
||||
_routes[name] = std::move(handler);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user