zsh-workers
 help / color / mirror / code / Atom feed
From: Marien Zwart <marien.zwart@gmail.com>
To: zsh-workers@zsh.org
Subject: segfault on 'echo $(< /dev/kmsg )' in zsh-5.0.2 and git
Date: Tue, 13 Aug 2013 20:53:12 +1000	[thread overview]
Message-ID: <CAEWfL_TiRLYLbhTuohZxw_XoN1z+dem-zxYODYepk8y1mooV3Q@mail.gmail.com> (raw)

Hello zsh-workers,

On zsh-5.0.2 as well as current git
(40a881569fed17177fbd73079dd4d3849517567c), the following segfaults on
my linux 3.10, glibc 2.17 system:

echo $(< /dev/kmsg )

Tracing through it in gdb, I've found that's because the fdopen(in,
"r") call in readoutput returned NULL (and then it predictably
segfaults somewhere in the subsequent fgetc). Sticking a NULL check
and zerr("fdopen: %e", errno); after the fdopen gets me "zsh: fdopen:
invalid argument", and returning NULL after that at least doesn't make
zsh immediately topple over. But I have no idea how safe that is
(there's no other error return in readoutput), and it needs some
tidying up such as closing the fd, so I'll leave properly patching
this to someone else.

That's assuming fdopen failing is considered possible. In this case,
it happens because /dev/kmsg supports seek but not with whence
SEEK_CUR, for which it fails with EINVAL (lseek(2) says "whence is not
valid" is one condition resulting in EINVAL), and glibc accepts that
seek failing with ESPIPE but not other reasons. Depending on which
manpage you read fdopen() may fail if fcntl fails, which it may do for
various reasons. So if it's not too hard it'd be nice for zsh to
survive fdopen failing, although there's something to be said for
fdopen (glibc) or the fd (linux kernel) being broken for this specific
crash (on /dev/kmsg).

-- 
Marien Zwart (marienz on freenode).


             reply	other threads:[~2013-08-13 10:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-13 10:53 Marien Zwart [this message]
2013-08-13 21:40 ` Axel Beckert
2013-08-14 14:42 ` Christian Neukirchen

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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

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

  git send-email \
    --in-reply-to=CAEWfL_TiRLYLbhTuohZxw_XoN1z+dem-zxYODYepk8y1mooV3Q@mail.gmail.com \
    --to=marien.zwart@gmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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).