Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 31 Dec 2015 15:10:32 +1100 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
Cc:        "Jonathan T. Looney" <jtl@freebsd.org>, src-committers@freebsd.org,  svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   Re: svn commit: r292955 - head/lib/libmd
Message-ID:  <20151231143314.Y1520@besplex.bde.org>
In-Reply-To: <20151231115651.R995@besplex.bde.org>
References:  <201512301804.tBUI4oGp065466@repo.freebsd.org> <20151231115651.R995@besplex.bde.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 31 Dec 2015, Bruce Evans wrote:

> 
> wc /proc/0/* works.  md5 works like wc using a hack to avoid calling this
> broken function.  E.g.,
>
>    for i in $(ls /proc/0/*); do echo -n "$i: "; md5 <$i; done  # gives
>
> /proc/0/cmdline: 3c5896b1ac441f4998f052e2126e8d20
> /proc/0/ctl: d41d8cd98f00b204e9800998ecf8427e
> /proc/0/etype: 674441960ca1ba2de08ad4e50c9fde98
> /proc/0/rlimit: 67d6ad67b412e1bceb7cb508a3492197
> /proc/0/status: 3ccc3067b97c3232ea2dbcb64c458fd4

Further examples:

     md5 # on terminal input

works correctly by not using MDXFileChunk().

     md5 /dev/stdin # on the same terminal input

produces the d41d8cd98f00b204e9800998ecf8427e garbage using
MDXFileChunk().  truss shows that lseek() is broken too -- MDXFileChunk()
tries it and it succeeds on the unseekable file /dev/stdin.  Bugs in this
area are common.  E.g., lseek() on named pipes was broken so that it
succeeded, by rearranging the plumbing use fileops more or less and not
attaching lseek right.

     cat | md5 # on the same terminal input

works correctly by not using MDXFileChunk().

     cat | md5 /dev/stdin # on the same terminal input

doesn't work correctly, but it fails better than without the pipe.  Now
a seek error occurs and is reported as "md5: /dev/stdin: Illegal seek"
(I can't see where it is reported).  Then md5 exits.  Then cat waits to
read input.  Then cat fails to write output and is killed by SIGPIPE.
So md5 handled the seek error in a fail-safe though incorrect way.  One
correct way is to fall back to the working code, but it is better to
just use that without an lseek check.

It is a bug that [l]stat() on /dev/stdin sees the device file and not the
actual stdin file.  md5 can't work around this except by not using stat().

Bruce



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20151231143314.Y1520>