Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent Variable Pointers #605

Open
Harlem512 opened this issue Sep 21, 2018 · 2 comments
Open

Inconsistent Variable Pointers #605

Harlem512 opened this issue Sep 21, 2018 · 2 comments

Comments

@Harlem512
Copy link

Memory addresses for class fields cycle when a super method is called, and its return value is stored.

As seen in the code snippet below, despite both Print methods being passed the exact same field, subVar, the first call returns the super class's field superVar.

class Super {
    superVar{_superVar}
    
    construct new(superVar) {
        _superVar="Super"
    }
    
    //This method doesn't even need to return anything
    method() { }
}
class Sub is Super {
    subVar{_subVar}
    
    construct new() {
        super()
        _subVar="Sub"
        System.print("Sub from Constructor: "+_subVar)      //Prints "Sub"
        System.print("Super from Constructor: "+superVar)   //Prints "Super"
        System.print("")
    }
    
    method() {
        //Storing the output causes this behavior
        //Reading _subVar before the method call still gives expected behavior
        var someName=super.method()
        System.print("Sub from Method: "+_subVar)    //Prints "Super" !
        System.print("Sub from Method: "+_subVar)    //Prints "Sub" !?!
    }
}

var sub=Sub.new()
sub.method()

This still happens no matter what names are given to the classes, their fields, or their methods and constructors, and even how _subVar is read.

Simply by storing the return value from a super call, the fields are messed up, until it _subVar is read again.

On a side note: using the syntax subVar instead of _subVar still allows for the proper behavior, and doing any operation on _subVar causes the address to be set back to normal.

method() {
        var someName=super.method()
        _subVar is String
        System.print("Sub from Method: "+_subVar)    //Prints "Sub"
        System.print("Sub from Method: "+_subVar)    //Prints "Sub"
}

This allows for reading of normally unreadable memory addresses, simply by adding more fields to the sub-class.

class Super {
    construct new() {
        //Private fields, not readable
        _super1="A"
        _super2="B"
        _super3="C"
    }
    
    method() {}
}
class Sub is Super {
    construct new() {
        super()
    }
    
    hackerman() {
        _hack1=null
        var ret1=super.method()
        System.print(_hack1)    //Prints "B", not "null"
        
        _hack2=null
        var ret2=super.method()
        System.print(_hack2)    //Prints "C", not "null"
    }
}

var sub=Sub.new()
sub.hackerman()
@mhermier
Copy link
Contributor

mhermier commented Sep 21, 2018 via email

@mhermier
Copy link
Contributor

mhermier commented Sep 22, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants