[vala] Deny access to protected constructors



commit 588c00e7e882de9bab1ecd256c1b90068fd8b554
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Sat Oct 8 22:13:01 2016 +0200

    Deny access to protected constructors
    
    Based on patch by Timm Bäder <mail baedert org>
    
    https://bugzilla.gnome.org/show_bug.cgi?id=760031

 tests/Makefile.am                      |    1 +
 tests/objects/bug760031.test           |   10 ++++++++++
 vala/valaobjectcreationexpression.vala |   10 +++++++---
 3 files changed, 18 insertions(+), 3 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index e10be4d..a9d0c18 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -178,6 +178,7 @@ TESTS = \
        objects/bug702736.vala \
        objects/bug702846.vala \
        objects/bug751338.vala \
+       objects/bug760031.test \
        objects/bug767092.test \
        objects/bug768823.test \
        objects/bug615830-1.test \
diff --git a/tests/objects/bug760031.test b/tests/objects/bug760031.test
new file mode 100644
index 0000000..5843982
--- /dev/null
+++ b/tests/objects/bug760031.test
@@ -0,0 +1,10 @@
+Invalid Code
+
+class Foo {
+       protected Foo () {
+       }
+}
+
+void main () {
+       new Foo ();
+}
diff --git a/vala/valaobjectcreationexpression.vala b/vala/valaobjectcreationexpression.vala
index 8481f44..0699503 100644
--- a/vala/valaobjectcreationexpression.vala
+++ b/vala/valaobjectcreationexpression.vala
@@ -173,7 +173,10 @@ public class Vala.ObjectCreationExpression : Expression {
                checked = true;
 
                if (member_name != null) {
-                       member_name.check (context);
+                       if (!member_name.check (context)) {
+                               error = true;
+                               return false;
+                       }
                }
 
                TypeSymbol type = null;
@@ -280,7 +283,8 @@ public class Vala.ObjectCreationExpression : Expression {
                                symbol_reference.version.check (source_reference);
                        }
 
-                       if (symbol_reference != null && symbol_reference.access == 
SymbolAccessibility.PRIVATE) {
+                       if (symbol_reference != null
+                           && (symbol_reference.access == SymbolAccessibility.PRIVATE || 
symbol_reference.access == SymbolAccessibility.PROTECTED)) {
                                bool in_target_type = false;
                                for (Symbol this_symbol = context.analyzer.current_symbol; this_symbol != 
null; this_symbol = this_symbol.parent_symbol) {
                                        if (this_symbol == cl) {
@@ -291,7 +295,7 @@ public class Vala.ObjectCreationExpression : Expression {
 
                                if (!in_target_type) {
                                        error = true;
-                                       Report.error (source_reference, "Access to private member `%s' 
denied".printf (symbol_reference.get_full_name ()));
+                                       Report.error (source_reference, "Access to non-public constructor 
`%s' denied".printf (symbol_reference.get_full_name ()));
                                        return false;
                                }
                        }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]