[interp] fix overflow corner cases for integer
[mono.git] / mono / metadata / mono-security.c
index 09b8cd44abe6deaba2428602aa257022dbf21a88..0d770f70cdc0906290840eeb398892843cfcdfb4 100644 (file)
@@ -19,7 +19,6 @@
 #include <mono/metadata/object-internals.h>
 #include <mono/metadata/metadata-internals.h>
 #include <mono/metadata/security.h>
-#include <mono/io-layer/io-layer.h>
 #include <mono/utils/strenc.h>
 
 #ifndef HOST_WIN32
@@ -227,7 +226,7 @@ ves_icall_System_Security_Principal_WindowsIdentity_GetTokenName (gpointer token
        gunichar2 *uniname = NULL;
        gint32 size = 0;
 
-       mono_error_init (&error);
+       error_init (&error);
 
        size = internal_get_token_name (token, &uniname);
 
@@ -337,15 +336,41 @@ ves_icall_System_Security_Principal_WindowsImpersonationContext_DuplicateToken (
 gboolean
 ves_icall_System_Security_Principal_WindowsImpersonationContext_SetCurrentToken (gpointer token)
 {
-       /* Posix version implemented in /mono/mono/io-layer/security.c */
+#ifdef HOST_WIN32
        return (ImpersonateLoggedOnUser (token) != 0);
+#else
+       uid_t itoken = (uid_t) GPOINTER_TO_INT (token);
+#ifdef HAVE_SETRESUID
+       if (setresuid (-1, itoken, getuid ()) < 0)
+               return FALSE;
+#endif
+       return geteuid () == itoken;
+#endif
 }
 
 gboolean
 ves_icall_System_Security_Principal_WindowsImpersonationContext_RevertToSelf (void)
 {
-       /* Posix version implemented in /mono/mono/io-layer/security.c */
+#ifdef HOST_WIN32
        return (RevertToSelf () != 0);
+#else
+#ifdef HAVE_GETRESUID
+       uid_t ruid, euid;
+#endif
+       uid_t suid = -1;
+
+#ifdef HAVE_GETRESUID
+       if (getresuid (&ruid, &euid, &suid) < 0)
+               return FALSE;
+#endif
+#ifdef HAVE_SETRESUID
+       if (setresuid (-1, suid, -1) < 0)
+               return FALSE;
+#else
+       return TRUE;
+#endif
+       return geteuid () == suid;
+#endif
 }
 #endif /* G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) */
 
@@ -524,10 +549,14 @@ ves_icall_Mono_Security_Cryptography_KeyPairPersistence_ProtectUser (MonoString
  * Note: Neither the structure nor the signature is verified by this function.
  */
 MonoBoolean
-ves_icall_System_Security_Policy_Evidence_IsAuthenticodePresent (MonoReflectionAssembly *refass)
+ves_icall_System_Security_Policy_Evidence_IsAuthenticodePresent (MonoReflectionAssemblyHandle refass, MonoError *error)
 {
-       if (refass && refass->assembly && refass->assembly->image) {
-               return (MonoBoolean)mono_image_has_authenticode_entry (refass->assembly->image);
+       error_init (error);
+       if (MONO_HANDLE_IS_NULL (refass))
+               return FALSE;
+       MonoAssembly *assembly = MONO_HANDLE_GETVAL (refass, assembly);
+       if (assembly && assembly->image) {
+               return (MonoBoolean)mono_image_has_authenticode_entry (assembly->image);
        }
        return FALSE;
 }
@@ -558,7 +587,7 @@ void invoke_protected_memory_method (MonoArray *data, MonoObject *scope, gboolea
        MonoMethod *method;
        void *params [2];
 
-       mono_error_init (error);
+       error_init (error);
        
        if (system_security_assembly == NULL) {
                system_security_assembly = mono_image_loaded ("System.Security");