LKML Archive on
help / color / mirror / Atom feed
From: Brent Casavant <>
To: Rick Jones <>
Cc:, David Miller <>,
Subject: Re: AF_UNIX MSG_PEEK bug?
Date: Tue, 8 Jan 2008 17:20:15 -0600 (CST)	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

On Tue, 8 Jan 2008, Rick Jones wrote:

> Potential bugs notwithstanding, given that this is a STREAM socket, and as
> such shouldn't (I hope, or I'm eating toes for dinner again) have side effects
> like tossing the rest of a datagram, why are you using MSG_PEEK?  Why not
> simply read the N bytes of the message that will have the message length with
> a normal read/recv, and then read that many bytes in the next call?

That's entirely reasonable, and probably a worthwhile change to make.
But, as you say, it doesn't change whether or not this is a bug in
the MSG_PEEK code.

With a small bit of complication I certainly can do what you suggest.

The initial reasoning was that this made it easy to handle the case where
the caller of the library routine (my code which stumbled on this was
part of a small library I wrote as part of the application) did not supply
a sufficiently sized buffer for reception of the next message.  The "easy"
way to do this was a MSG_PEEK to validate the buffer size against the
message size, followed by a regular recv() if the buffer is large enough.
To do what you suggest (which effectively works around the bug) is certainly
possible, but also requires maintaining state between calls to the
"get message" routine, as I need to track whether or not the size has already
been read from the next message on the stream socket.

The change isn't terribly difficult, but wasn't the initial idea.

Plus it's always good to flush a bug out of hiding, right? ;)


Brent Casavant                          All music is folk music.  I ain't                        never heard a horse sing a song.
Silicon Graphics, Inc.                    -- Louis Armstrong

  parent reply	other threads:[~2008-01-08 23:20 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-08 22:27 Brent Casavant
2008-01-08 22:40 ` Rick Jones
2008-01-08 22:53   ` Tom Spink
2008-01-08 23:18     ` Brent Casavant
2008-01-08 23:39       ` Tom Spink
2008-01-08 23:46         ` Tom Spink
2008-01-09  0:08           ` Brent Casavant
2008-01-08 23:20   ` Brent Casavant [this message]
2008-01-09 11:04 ` Tetsuo Handa
2008-01-09 18:01   ` Brent Casavant
2008-01-10  0:01     ` Herbert Xu
2008-01-10  1:19       ` Brent Casavant
2008-01-10  2:50       ` Brent Casavant
2008-01-10 22:35         ` Brent Casavant
2008-01-10 22:36           ` Alan Cox

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \
    --subject='Re: AF_UNIX MSG_PEEK bug?' \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).