From 403e74d159d0937e5e0f5c67a59483b8fce41890 Mon Sep 17 00:00:00 2001
From: licunlong <licunlong1@huawei.com>
Date: Fri, 14 Jul 2023 15:47:15 +0800
Subject: [PATCH] fix: check if the message is truncated

---
 core/sysmaster/unit/notify.rs | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/core/sysmaster/unit/notify.rs b/core/sysmaster/unit/notify.rs
index f35ed91..4f3cc15 100644
--- a/core/sysmaster/unit/notify.rs
+++ b/core/sysmaster/unit/notify.rs
@@ -224,6 +224,12 @@ impl Notify {
         let msgs = socket::recvmsg::<()>(self.rawfd(), &mut iov, Some(&mut space), flags)
             .context(NixSnafu)?;
 
+        if msgs.flags.contains(MsgFlags::MSG_CTRUNC) {
+            return Err(Error::Nix {
+                source: nix::Error::EXFULL,
+            });
+        }
+
         // check: peek == pop
         let (received_cred, received_fds) = notify_trans_recvmsg(&msgs);
         if get_pid_from_cred(&received_cred) != pid {
@@ -279,6 +285,12 @@ fn notify_peek_pid(fd: RawFd, flags: MsgFlags) -> Result<libc::pid_t> {
     let msgs =
         socket::recvmsg::<()>(fd, &mut iov, Some(&mut space), peek_flags).context(NixSnafu)?;
 
+    if msgs.flags.contains(MsgFlags::MSG_CTRUNC) {
+        return Err(Error::Nix {
+            source: nix::Error::EXFULL,
+        });
+    }
+
     // get message information
     let (received_cred, received_fds) = notify_trans_recvmsg(&msgs);
     for fd in received_fds.iter() {
-- 
2.33.0

