Groups | Blog | Home
all groups > dotnet security > september 2004 >

dotnet security : FileIOPermission throws System.ExecutionEngineException


Nicole Calinoiu
9/23/2004 8:36:31 AM
A few questions:

1. Does your code apply any stack walk modifiers (Assert, PermitOnly, or
Deny)?
2. If you replace the FileIOPermission demand by the unmanaged code demand
(i.e.: run the latter from the same place in your code as the former), do
you still get the exception?
3. Would you mind providing the full exception details, retrieved via its
ToString method?



[quoted text, click to view]

Andreas Håkansson
9/23/2004 2:02:24 PM
While working at a small application, and trying to be a good .net citizen I
perform
a check to see if the executing code has permission to work with files in a
specific
directory, like this

Dim FilePerm As FileIOPermission = _
New FileIOPermission(FileIOPermissionAccess.AllAccess,
Path.GetDirectoryName(FileName))
FilePerm.Demand()

However, when the code hits the call to the Demand method it throws an
ExecutionEngineException with the message

"Unable to retrieve security descriptor for this frame."

The application is a WinForm application and in the Main method I assign the
current users principal to the current thread like this

Shared Sub main()

Dim WinUser As WindowsIdentity = _
WindowsIdentity.GetCurrent()
Dim WinPrincipal As New WindowsPrincipal(WinUser)
System.Threading.Thread.CurrentThread.CurrentPrincipal =
WinPrincipal

Dim main As New MainForm
Application.Run(main)

End Sub

Any ideas to the reason for this?

//Andreas

Andreas Håkansson
9/23/2004 2:08:50 PM
I can add to the equation that about 10 lines further down the code I
perform the following check

Dim UnmanagedPerm As SecurityPermission = _
New SecurityPermission(SecurityPermissionFlag.UnmanagedCode)
UnmanagedPerm.Demand()

Without any problems. I have disabaled the FileIO security check pending
some feedback, thus I know that this code is executed flawless =/

And if it is of any help, the code I'm working on is controlled by VSS.

//Andreas


"Andreas Håkansson" <andreas.hakansson@nospam.com> skrev i meddelandet
news:%23g9wlUWoEHA.3988@tk2msftngp13.phx.gbl...
[quoted text, click to view]

Andreas Håkansson
9/23/2004 3:17:57 PM
Nicole,

As I was about to test (2) I found that I had left an old RevertAll() call
in
the code which was the source of the exception. Since all I did was call
the Demand method on my permission, the RevertAll call was bound to
fail.

User error strikes again! =)

Thanks for taking the time.


"Nicole Calinoiu" <ngcalinoiu REMOVETHIS AT gmail DOT com> skrev i
meddelandet news:ugaU7nWoEHA.3460@TK2MSFTNGP10.phx.gbl...
[quoted text, click to view]

AddThis Social Bookmark Button