zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: Markus Trippelsdorf <markus@trippelsdorf.de>
Cc: zsh-workers@zsh.org
Subject: Re: Two issues found with -fsanitize=undefined
Date: Sat, 19 Sep 2015 23:35:28 +0100	[thread overview]
Message-ID: <20150919233528.41828582@ntlworld.com> (raw)
In-Reply-To: <20150919201814.GA409@x4>

On Sat, 19 Sep 2015 22:18:14 +0200
Markus Trippelsdorf <markus@trippelsdorf.de> wrote:
> ./D02glob.ztst: starting.
> exec.c:2240:6: runtime error: index 8 out of bounds for type 'int [8]'
> exec.c:2048:10: runtime error: index 8 out of bounds for type 'int [8]'
> exec.c:2122:7: runtime error: index 8 out of bounds for type 'int [8]'
 
MULTIOUNIT is 8. struct multio is defined as

struct multio {
    int ct;		/* # of redirections on this fd                 */
    int rflag;		/* 0 if open for reading, 1 if open for writing */
    int pipe;		/* fd of pipe if ct > 1                         */
    int fds[MULTIOUNIT]; /* list of src/dests redirected to/from this fd */
};

so something is probably up here when ct is 8 and the structure needs
reallocating.

	if (mfds[fd1]->ct == 1) {	/* split the stream */
           /* ... */
	} else {		/* add another fd to an already split stream */
	    int fdN;
	    if(!(mfds[fd1]->ct % MULTIOUNIT)) {
		int new = sizeof(struct multio) + sizeof(int) * mfds[fd1]->ct;
		int old = new - sizeof(int) * MULTIOUNIT;
		mfds[fd1] = hrealloc((char *)mfds[fd1], old, new);
	    }
	    if ((fdN = movefd(fd2)) < 0) {
		zerr("multio failed for fd %d: %e", fd2, errno);
		closemnodes(mfds);
		return;
	    }
	    mfds[fd1]->fds[mfds[fd1]->ct++] = fdN;
	}

However, it looks right.  You end up with MULTIOUNIT + ct fd's
available, which is what you want: ct goes from 8 to 9 with index 8
being used out of 0 to 15 allocated.  The zerr() before the return means
it doesn't matter if we don't actually increment ct as the structure is
never used (memory is on the heap).

It may be the compiler isn't actually looking at the memory allocated,
only the definition of the structure.  Certainly valgrind has never
complained here and this is something it should pick up.

pws


  reply	other threads:[~2015-09-19 22:35 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-17  7:57 Markus Trippelsdorf
2015-09-17 17:16 ` Bart Schaefer
2015-09-17 17:24   ` Markus Trippelsdorf
2015-09-17 17:41     ` Bart Schaefer
2015-09-19 19:57 ` Peter Stephenson
2015-09-19 20:18   ` Markus Trippelsdorf
2015-09-19 22:35     ` Peter Stephenson [this message]
2015-09-20  4:09       ` Bart Schaefer
2015-09-21 12:46   ` Peter Stephenson
2015-09-21 19:13 ` Peter Stephenson
2015-09-21 20:04   ` Markus Trippelsdorf
2015-09-21 20:21     ` Peter Stephenson
2015-09-21 20:34       ` Markus Trippelsdorf
2015-09-21 20:56         ` Bart Schaefer
2015-09-22  0:02           ` Markus Trippelsdorf

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=20150919233528.41828582@ntlworld.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=markus@trippelsdorf.de \
    --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).