This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 8756b596abcd0fe4af45bf349d1125c0628cdc80
Author: Marco Casaroli <[email protected]>
AuthorDate: Tue Nov 3 14:25:36 2026 +0100

    sched/mqueue: Limit the message type of msgrcv() with a negative msgtyp.
    
    msgrcv() with msgtyp < 0 took the message of the lowest type in the
    whole queue.  POSIX says: the first message of the lowest type that is
    less than or equal to the absolute value of msgtyp.  With only a
    message of type 3 in the queue, msgrcv(-2) received it.
    
    Skip the messages with a higher type.  If no message fits, msgrcv()
    blocks, or gives ENOMSG with IPC_NOWAIT, as for a positive msgtyp.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 sched/mqueue/msgrcv.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/sched/mqueue/msgrcv.c b/sched/mqueue/msgrcv.c
index 7860e6f79a3..e8e9947d232 100644
--- a/sched/mqueue/msgrcv.c
+++ b/sched/mqueue/msgrcv.c
@@ -85,7 +85,10 @@ static int msgrcv_wait(FAR struct msgq_s *msgq, FAR struct 
msgbuf_s **rcvmsg,
 
           if (msgtyp < 0)
             {
-              if (newmsg == NULL || newmsg->mtype > tmp->mtype)
+              /* mtype <= |msgtyp|, without the overflow of -LONG_MIN */
+
+              if (-tmp->mtype >= msgtyp &&
+                  (newmsg == NULL || newmsg->mtype > tmp->mtype))
                 {
                   newmsg = tmp;
                 }

Reply via email to