Re: Problem with msgsnd

From: Marc Schneider (Marc_Schneider@ers.com)
Date: Thu Oct 26 2000 - 10:15:30 EST


lkml@dm.ultramaster.com wrote:
>
> Marc Schneider wrote:
> >
> > msgsnd seems to be corrupting memory around the msgbuf pointer.
> >
> > for example I have the following code:
> >
> > pMsgBuf = malloc(iPacketLen + 4 + 8);
> > bzero(pMsgBuf, iPacketLen + 4 + 8);
> > pMsgBuf += 4; /* Build a guard band */
> >
> > printf("PMQ:pMsgBuf: %p\n",pMsgBuf);
> > printf("PMQ:-4: %p\n", *(pMsgBuf-4));
> >
> > rc = msgsnd(iMsgQueueID, pMsgBuf, iPacketLen, 0);
> >
>
> Two issues which may or may not directly address your problem. Quoting
> the man page:
>
> ..The structure member mtype must have a
> strictly positive integer value that can be used by the
> receiving process for message selection (see the section
> about msgrcv).
>
> Here, your 'mtype', the long at the beginning of the message, is 0.
>
> Secondly, the third parameter to msgsnd is the size of the data portion
> of the message, not the 'packetlen.' Usually msgsnd is passed a
>
> structure pointer, say a struct msgbuf *. In that case, msgsz is:
> sizeof(struct msgbuf) - sizeof(long).
>
> The first issue makes anything possible... The second is just a gotcha
> to avoid.
>
> David Mansfield

I don't actually show it in the above code snippet but, I do copy data
into the buffer pointed by pMsgBuf. The first four bytes is a long which
take a value between 1 and 20.

The actual data follows the four bytes. The amount of data copied is
specified by iPacketLen. My buffer is actually iPacketLen+4 bytes in
size. (The guard band of four bytes before and after the buffer is
actually not used and is only there to detect this error.)

Any other Ideas?

Marc Schneider
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Tue Oct 31 2000 - 21:00:18 EST