Click here to Skip to main content
15,898,036 members
Home / Discussions / C#
   

C#

 
AnswerRe: visual studio express - stand alone app ? Pin
Dave Kreskowiak18-Oct-06 17:51
mveDave Kreskowiak18-Oct-06 17:51 
GeneralRe: visual studio express - stand alone app ? Pin
bryce18-Oct-06 18:25
bryce18-Oct-06 18:25 
AnswerRe: visual studio express - stand alone app ? Pin
Guffa18-Oct-06 18:34
Guffa18-Oct-06 18:34 
QuestionSending WM_CONTEXTMENU Pin
cmaissan18-Oct-06 16:23
cmaissan18-Oct-06 16:23 
QuestionHow to Check when a computer is connected to internet Pin
FlyOnIT18-Oct-06 15:55
FlyOnIT18-Oct-06 15:55 
AnswerRe: How to Check when a computer is connected to internet Pin
seee sharp19-Oct-06 21:46
seee sharp19-Oct-06 21:46 
GeneralRe: How to Check when a computer is connected to internet Pin
FlyOnIT23-Oct-06 6:29
FlyOnIT23-Oct-06 6:29 
QuestionStructLayoutAttribute and type safety Pin
Vega0218-Oct-06 14:30
Vega0218-Oct-06 14:30 
So I have the following structure definition:

    [StructLayout(LayoutKind.Explicit)]<br />
    struct MyStruct<br />
    {<br />
        [FieldOffset(0)]<br />
        public float f;<br />
<br />
        [FieldOffset(0)]<br />
        public int i;<br />
<br />
        [FieldOffset(4)]<br />
        public object o;<br />
<br />
        [FieldOffset(4)]<br />
        public ArrayList al;<br />
    }


And the following program:

static void Main(string[] args)<br />
{<br />
    MyStruct s;<br />
    s.i = 1;<br />
    s.f = 1.0f;<br />
    s.al = null;<br />
    s.o = new object();<br />
    Console.WriteLine("float = {0}", s.f);<br />
    Console.WriteLine("int = {0:x}", s.i);<br />
    Console.WriteLine("object = {0}", s.o);<br />
    Console.WriteLine("arraylist = {0}", s.al);<br />
    Console.WriteLine("arraylen = {0}", s.al.Capacity);<br />
    s.al.Remove(s.o);<br />
    Console.ReadLine();<br />
}


Essentially, I'm forcing an ArrayList reference to point to an object of type Object, then calling ArrayList member functions on that Object. As you might imagine, this leads to some fairly disastrous consequences in the runtime. Calling various members of the ArrayList results in an exception being thrown:

s.al.Add(s.o): RemotingException ("Cannot load type")
s.al.Remove(s.o): AccessViolationException
s.al.BinarySearch(s.o): SEHException

Obviously this program is no longer type-safe, but running the peverify utility on the generated executable gives a thumbs-up. All of this brings me to the actual question.. is this the intended behavior of the language and runtime, or is this a bug?

Googling brings me to http://discuss.develop.com/archives/wa.exe?A2=ind0112c&L=dotnet&D=0&P=53651, but this was written five years ago and doesn't actually provide an answer to the question. What do you guys think about this behavior? Am I justified in seeing this as a security vulnerability (perhaps a plugin commits a privilege escalation attack) rather than a simple bug?
GeneralRe: StructLayoutAttribute and type safety Pin
Werdna19-Oct-06 7:03
Werdna19-Oct-06 7:03 
GeneralRe: StructLayoutAttribute and type safety Pin
Vega0219-Oct-06 16:48
Vega0219-Oct-06 16:48 
QuestionProcess.ProccessName coming up idle in seperate thread. Pin
Sunset Towers18-Oct-06 12:02
Sunset Towers18-Oct-06 12:02 
GeneralRe: Process.ProccessName coming up idle in seperate thread. [modified] Pin
Anthony Mushrow18-Oct-06 13:55
professionalAnthony Mushrow18-Oct-06 13:55 
AnswerRe: Process.ProccessName coming up idle in seperate thread. Pin
Anthony Mushrow18-Oct-06 14:24
professionalAnthony Mushrow18-Oct-06 14:24 
GeneralRe: Process.ProccessName coming up idle in seperate thread. Pin
Sunset Towers18-Oct-06 15:10
Sunset Towers18-Oct-06 15:10 
Questionmake a class property an array of an instantiated class? Pin
mmatteson18-Oct-06 11:56
mmatteson18-Oct-06 11:56 
AnswerRe: make a class property an array of an instantiated class? Pin
Christian Graus18-Oct-06 11:59
protectorChristian Graus18-Oct-06 11:59 
GeneralRe: make a class property an array of an instantiated class? Pin
mmatteson19-Oct-06 6:10
mmatteson19-Oct-06 6:10 
AnswerRe: make a class property an array of an instantiated class? Pin
Andrew Rissing18-Oct-06 12:16
Andrew Rissing18-Oct-06 12:16 
GeneralRe: make a class property an array of an instantiated class? Pin
mmatteson18-Oct-06 16:32
mmatteson18-Oct-06 16:32 
QuestionGraphics Pin
Areff18-Oct-06 10:59
Areff18-Oct-06 10:59 
AnswerRe: Graphics Pin
Christian Graus18-Oct-06 11:03
protectorChristian Graus18-Oct-06 11:03 
GeneralRe: Graphics Pin
Areff18-Oct-06 11:12
Areff18-Oct-06 11:12 
GeneralRe: Graphics Pin
Christian Graus18-Oct-06 11:33
protectorChristian Graus18-Oct-06 11:33 
GeneralRe: Graphics Pin
V.19-Oct-06 4:51
professionalV.19-Oct-06 4:51 
AnswerRe: Graphics Pin
V.19-Oct-06 4:50
professionalV.19-Oct-06 4:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.