220 10940 <CANh-dXnFeO-SRSYkxf3r=nDxg=OKakUSKegG_zYoh1sq3L=qBw@mail.gmail.com> article
Path: news.gmane.org!not-for-mail
From: "'Jeffrey Yasskin' via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Protect Lambda functions against reflection
Date: Wed, 28 May 2014 15:27:14 -0700
Lines: 81
Approved: news@gmane.org
Message-ID: <CANh-dXnFeO-SRSYkxf3r=nDxg=OKakUSKegG_zYoh1sq3L=qBw@mail.gmail.com>
References: <108c47a2-d952-4f84-a347-923b2ab742ad@isocpp.org>
 <CAFk2RUaPcXONmVug7-_t+imouCVQv9LQ3Hos-yRo=0X-HBQZKQ@mail.gmail.com>
 <CAB+4KHL3MvqYR3s=grM7t8imKHmnjj8s4PAYO01Z+rtq8sivnw@mail.gmail.com>
 <CAFk2RUasQdm4U+w393wqaD-J_6km+xOHhmd_sRyBx7ESy5Eyjw@mail.gmail.com>
 <CAB+4KH+eoF=PcS1pTg+neNA60bcbyZZXJsUenud4Md5RAk+MKw@mail.gmail.com>
 <CAFk2RUacOGaupA6+4JnYMt9ADv4vLOnXL6Ye4ef6crmOB7p78w@mail.gmail.com>
 <CAB+4KHJa1_OoQ5fevDztHYUJDz=uoW5BgzOAiNX19ArNyQhCvg@mail.gmail.com>
 <CAFk2RUbRbXCCETeD=PC3yCHJSigqiCqaCYM8NUx57tugnw4m7w@mail.gmail.com>
 <CANh-dXm+2BcZr-2mcoK_sjOnPgZoczN29A1ZBxQ5xvnOpnwL0A@mail.gmail.com>
 <CAB+4KHJJG=M7PbGJrconmROoOSJPt3hK7CpnD9BWYeSOrEUTXA@mail.gmail.com>
 <7ef3d3da-0c1d-443c-88d2-656b91937170@isocpp.org> <68f98b78-8bd4-48e0-9e1d-47cfc0492764@isocpp.org>
 <CAGg_6+MbbEPCW8mxyDDCZJhrhDKideb_UBvQ42De46w-WRGhjw@mail.gmail.com> <af9ceb0c-e51e-446e-8f56-bc58a2144896@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
X-Trace: ger.gmane.org 1401316063 9894 80.91.229.3 (28 May 2014 22:27:43 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 28 May 2014 22:27:43 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDDM34EO6QDRBV6FTGOAKGQE6BVD5KQ@isocpp.org Thu May 29 00:27:37 2014
Return-path: <std-proposals+bncBDDM34EO6QDRBV6FTGOAKGQE6BVD5KQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ve0-f199.google.com ([209.85.128.199])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDDM34EO6QDRBV6FTGOAKGQE6BVD5KQ@isocpp.org>)
	id 1WpmJs-0004AT-S3
	for gclcip-std-proposals@m.gmane.org; Thu, 29 May 2014 00:27:37 +0200
Original-Received: by mail-ve0-f199.google.com with SMTP id oz11sf47302832veb.10
        for <gclcip-std-proposals@m.gmane.org>; Wed, 28 May 2014 15:27:36 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:mime-version:in-reply-to:references:from:date
         :message-id:subject:to:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe:content-type;
        bh=jqnlcDwiorRtxE1RA+q0OpXKJd9SOVQQv/suVowlOQQ=;
        b=UqIjmmv6Vd2hC+s14h2vN8TZh9RHl7kawEaITcuviZzSCbCjTnLKoaNnytQJ8sEnnk
         nOY0gHlY8k+XuImvsfK90UGJjEIHlfyVLtEAr0BhdYssPQVbvw9rS+FFcPluoOwjBGvw
         btHoba6ugm2CLofwRzvjTwiOJAHQcpVzTwOZ8YJ4yizLq5woNebuWXvTZM6SyMuK0IaD
         x7d+UBptnsTHAR0nI0eSYM3T1ufaGkUf64eTk0TwqWjHOxEtZisHV/WvrNXyH2KtJZtP
         IIqceWpjYMTvYQG+AQEMKVoA3+dv3idm/onTcFh2xl4+gyWn0Kyvxubl1pn9wVwTN/RZ
         I/Fw==
X-Gm-Message-State: ALoCoQms6cvpUliocBJZe8oQW77zos9ZruCg6wcD56S4UCw7fiX/4ID330XoUUMSrUqLgNSzo+TI
X-Received: by 10.58.38.199 with SMTP id i7mr1324633vek.6.1401316055986;
        Wed, 28 May 2014 15:27:35 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.109.247 with SMTP id l110ls338820qgf.90.gmail; Wed, 28 May
 2014 15:27:35 -0700 (PDT)
X-Received: by 10.224.114.145 with SMTP id e17mr3914510qaq.53.1401316055323;
        Wed, 28 May 2014 15:27:35 -0700 (PDT)
Original-Received: from mail-qg0-x232.google.com (mail-qg0-x232.google.com [2607:f8b0:400d:c04::232])
        by mx.google.com with ESMTPS id 95si23659397qgt.50.2014.05.28.15.27.35
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Wed, 28 May 2014 15:27:35 -0700 (PDT)
Received-SPF: pass (google.com: domain of jyasskin@google.com designates 2607:f8b0:400d:c04::232 as permitted sender) client-ip=2607:f8b0:400d:c04::232;
Original-Received: by mail-qg0-f50.google.com with SMTP id z60so19685810qgd.37
        for <std-proposals@isocpp.org>; Wed, 28 May 2014 15:27:35 -0700 (PDT)
X-Received: by 10.224.163.8 with SMTP id y8mr4288543qax.46.1401316055147; Wed,
 28 May 2014 15:27:35 -0700 (PDT)
Original-Received: by 10.229.139.79 with HTTP; Wed, 28 May 2014 15:27:14 -0700 (PDT)
In-Reply-To: <af9ceb0c-e51e-446e-8f56-bc58a2144896@isocpp.org>
X-Original-Sender: jyasskin@google.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of jyasskin@google.com designates 2607:f8b0:400d:c04::232 as permitted
 sender) smtp.mail=jyasskin@google.com;       dkim=pass header.i=@google.com;
       dmarc=pass (p=REJECT dis=NONE) header.from=google.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
X-Original-From: Jeffrey Yasskin <jyasskin@google.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:10940
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/10940>

On Wed, May 28, 2014 at 2:48 PM, Diggory Blake <diggsey@googlemail.com> wrote:
>
>
> On Wednesday, 28 May 2014 22:18:24 UTC+1, Nevin ":-)" Liber wrote:
>>
>> On 28 May 2014 15:38, Diggory Blake <dig...@googlemail.com> wrote:
>>>
>>> Also, access modifiers are not there for security reasons - it's trivial
>>> to bypass them if one really wanted to
>>
>>
>> While there are a few places in the language where encapsulation is broken
>> (templated member functions, for instance), I don't think it is trivial to
>> bypass them in a standard conforming C++ program.  Could you give us some
>> simple examples?
>
>
> struct Foo {
> public:
>     int m_public;
> private:
>     int m_private;
> };
>
> struct Bar {
> public:
>     int m_public;
>     int m_private;
> };
>
> void setPrivate(Foo* foo, int v) {
>     ((Bar*)foo)->m_private = v;
> }
>
> C++ allows direct memory access, of course it's trivial to bypass any kind
> of access control not enforced by the underlying operating system.

This violates basic.lval's aliasing restrictions, which causes
undefined behavior. It also relies on the compiler not taking
advantage of the permission to reorder things at access control
boundaries. That's why Nevin specified "standard conforming". It's
true that malicious code within a single process can, in practice, use
undefined behavior to get whatever behavior it wants, but undefined
behavior still affects who's blamed for breakage.

>>> Since reflection is a tool used by the program, not the programmer,
>>
>>
>> Huh?
>
>
> The purpose of reflection is not to do this (pseudocode):
> findClass("Foo").construct("Hello, world!")
>
> Instead of just:
> new Foo("Hello, world!")
>
> If the programmer was the one supplying these arguments then it would be
> pointless.

If Foo's constructor is private, but reflection allows access to it
anyway, people will use reflection to get access to it, and the people
trying to maintain Foo will curse us the next time they try to upgrade
it. You saying that's not the purpose won't stop any of that from
happening.

That said, I think I do prefer reflection to ignore access control,
and not to provide an escape hatch for class authors. If class authors
can't explicitly block reflection, it'll be a bit easier for them to
place the blame on the "nitwits" where it belongs. :)

Jeffrey

-- 

--- 
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

.
