zsh-workers
 help / color / mirror / code / Atom feed
From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: Roman Perepelitsa <roman.perepelitsa@gmail.com>
Cc: Peter Stephenson <p.w.stephenson@ntlworld.com>,
	Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: 5.8: LTO exposes some new issues
Date: Tue, 28 Jul 2020 11:19:55 +0000	[thread overview]
Message-ID: <20200728111956.21617dde@tarpaulin.shahaf.local2> (raw)
In-Reply-To: <CAN=4vMp0GP=JJrfP=N6q7s_yCXp-_LMJBL1dC8Kd2weMNPvm0A@mail.gmail.com>

Roman Perepelitsa wrote on Tue, 28 Jul 2020 12:52 +0200:
> On Tue, Jul 28, 2020 at 10:26 AM Peter Stephenson
> <p.w.stephenson@ntlworld.com> wrote:
> >  
> > > On 28 July 2020 at 08:53 Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> > >
> > > It's clearly correct, but as written, the patch loses the distinction
> > > that these members are private to hashtable.c and should not be accessed
> > > by other parts of the code.  Could you address that, please?  If
> > > there's an easy way to have the compiler enforce this restriction,
> > > great; else, we can at least add a comment.  
> >
> > One way is to have a "struct { ... } private" substructure,
> > which it makes it clear what's going on within the code (though comments
> > are obviously useful, too).  
> 
> How about this? The diff is a bit larger but the code is fairly
> straightforward. Only hashtable.c has access to internal fields, just
> like before the patch.
> 
> In a nutshell, struct hashtable has only public data members. Within
> hashtable.c there is struct hashtableimpl, which has struct hashtable
> as the first data member. C allows casting a pointer to a struct to a
> pointer to its first data member and back without violating aliasing
> rules. Thus hashtable.c can cast struct hashtable* to struct
> hashtableimpl* in order to get access to internal fields.

Thanks, that addresses the previous point, but unfortunately it creates
another problem: people who read the .h file are liable to declare
local variables of type 'struct hashtable', or memcpy() them around,
and in either case, once such a variable gets to hashtable.c and the
private members are accessed, we'll get out-of-bounds reads.

So we need either a comment at the definition of the struct type that
says nobody should allocate/duplicate/assign such structs directly, but
call newhashtable() instead, or a solution that doesn't involve casts,
such as Peter's proposal.

Cheers,

Daniel

  reply	other threads:[~2020-07-28 11:21 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-21 23:41 Tomasz Kłoczko
2020-07-22  5:59 ` Daniel Shahaf
2020-07-25 17:43   ` Bart Schaefer
     [not found]     ` <CABB28CxSD5w-SY-iCVYuQ4kJfBpNJOWhpk4HOrS1DNPfMVztgw@mail.gmail.com>
2020-07-25 20:05       ` Fwd: " Bart Schaefer
2020-07-27  2:12         ` Daniel Shahaf
2020-07-27 10:07           ` Tomasz Kłoczko
2020-07-27 11:09             ` Roman Perepelitsa
2020-07-27 12:19               ` Roman Perepelitsa
2020-07-27 12:46                 ` Tomasz Kłoczko
2020-07-27 14:13                   ` Roman Perepelitsa
2020-07-27 14:19                   ` Roman Perepelitsa
2020-07-28  8:09                     ` Daniel Shahaf
2020-07-28 10:55                     ` Fwd: " Roman Perepelitsa
2020-07-28  8:19                   ` Daniel Shahaf
2020-07-28  7:53                 ` Daniel Shahaf
2020-07-28  8:25                   ` Peter Stephenson
2020-07-28 10:52                     ` Roman Perepelitsa
2020-07-28 11:19                       ` Daniel Shahaf [this message]
2020-07-28 11:31                         ` Roman Perepelitsa
2020-07-28 11:51                           ` Daniel Shahaf

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=20200728111956.21617dde@tarpaulin.shahaf.local2 \
    --to=d.s@daniel.shahaf.name \
    --cc=p.w.stephenson@ntlworld.com \
    --cc=roman.perepelitsa@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).