tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Expected msgrcv(2) behaviour with msgsz > SSIZE_MAX ?



On Sat, Jan 03, 2009 at 12:25:32PM +0100, Nicolas Joly wrote:
> On Fri, Jan 02, 2009 at 04:50:32PM +0000, Christos Zoulas wrote:
[...]
> > The manual page needs to be fixed to remove the comment that < 0 == EINVAL,
> > and say that:
> > 
> > In this implementation if the value of msgsz exceeds SSIZE_MAX,
> > .Fn msgrcv 
> > will wait forever for a message to arrive.
> > 
> > or we should just check and return -1/E2BIG or EINVAL, which seems more
> > useful to me.
[...]
> Will try to prepare a patch in the next few days ...

Sorry for the delay. Here it is.

-- 
Nicolas Joly

Biological Software and Databanks.
Institut Pasteur, Paris.
Index: sys/kern/sysv_msg.c
===================================================================
RCS file: /cvsroot/src/sys/kern/sysv_msg.c,v
retrieving revision 1.59
diff -u -p -r1.59 sysv_msg.c
--- sys/kern/sysv_msg.c 11 Jan 2009 02:45:53 -0000      1.59
+++ sys/kern/sysv_msg.c 24 Jan 2009 13:41:05 -0000
@@ -653,6 +653,10 @@ msgsnd1(struct lwp *l, int msqidr, const
 
        MSG_PRINTF(("call to msgsnd(%d, %p, %lld, %d)\n", msqid, user_msgp,
            (long long)msgsz, msgflg));
+
+       if ((ssize_t)msgsz < 0)
+               return EINVAL;
+
 restart:
        msqid = IPCID_TO_IX(msqidr);
 
@@ -959,6 +963,10 @@ msgrcv1(struct lwp *l, int msqidr, char 
 
        MSG_PRINTF(("call to msgrcv(%d, %p, %lld, %ld, %d)\n", msqid,
            user_msgp, (long long)msgsz, msgtyp, msgflg));
+
+       if ((ssize_t)msgsz < 0)
+               return EINVAL;
+
 restart:
        msqid = IPCID_TO_IX(msqidr);
 
Index: lib/libc/sys/msgrcv.2
===================================================================
RCS file: /cvsroot/src/lib/libc/sys/msgrcv.2,v
retrieving revision 1.17
diff -u -p -r1.17 msgrcv.2
--- lib/libc/sys/msgrcv.2       13 May 2004 10:20:58 -0000      1.17
+++ lib/libc/sys/msgrcv.2       24 Jan 2009 13:41:05 -0000
@@ -173,7 +173,8 @@ The message queue was removed while
 was waiting for a message of the requested type to become available in it.
 .Pp
 .Fa msgsz
-is less than 0.
+is greater than
+.Dv SSIZE_MAX .
 .It Bq Er E2BIG
 A matching message was received, but its size was greater than
 .Fa msgsz
Index: lib/libc/sys/msgsnd.2
===================================================================
RCS file: /cvsroot/src/lib/libc/sys/msgsnd.2,v
retrieving revision 1.15
diff -u -p -r1.15 msgsnd.2
--- lib/libc/sys/msgsnd.2       13 May 2004 10:20:58 -0000      1.15
+++ lib/libc/sys/msgsnd.2       24 Jan 2009 13:41:05 -0000
@@ -141,8 +141,10 @@ was waiting for a resource to become ava
 message.
 .Pp
 .Fa msgsz
-is less than 0, or greater than
-.Va msg_qbytes .
+is greater than
+.Va msg_qbytes
+or
+.Dv SSIZE_MAX .
 .It Bq Er EACCES
 The calling process does not have write access to the message queue.
 .It Bq Er EAGAIN


Home | Main Index | Thread Index | Old Index