Skip to content

Commit 96eb5e3

Browse files
authored
Use DefaultDllImportSearchPathsAttribute (#66)
Fixes #64 Context: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1139578 Context: https://liquid.microsoft.com/Web/Object/Read/ms.security/Requirements/Microsoft.Security.SystemsADM.10039#guide The current security guidance is that the [`System.Runtime.InteropServices.DefaultDllImportSearchPathsAttribute`](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.defaultdllimportsearchpathsattribute?view=netcore-3.1) attribute should be placed either on the assembly or on `[DllImport]` methods, to control and constrain where [`LoadLibraryEx()`](https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexa?redirectedfrom=MSDN) will look for native libraries. This commit implements this in the `Native.cs` file. We are using an assembly level atribute but place it in the area where all the native calls are maintained.
1 parent 755a42a commit 96eb5e3

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

Diff for: Native.cs

+13-11
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
using System;
2828
using System.Runtime.InteropServices;
2929

30+
[assembly: DefaultDllImportSearchPathsAttribute(DllImportSearchPath.SafeDirectories)]
31+
3032
namespace Xamarin.Tools.Zip
3133
{
3234
internal class Native
@@ -47,16 +49,16 @@ public struct zip_source_args_seek_t
4749

4850
public struct zip_stat_t
4951
{
50-
public UInt64 valid; /* which fields have valid values */
51-
public IntPtr name; /* name of the file (char *) */
52-
public UInt64 index; /* index within archive */
53-
public UInt64 size; /* size of file (uncompressed) */
54-
public UInt64 comp_size; /* size of file (compressed) */
55-
public IntPtr mtime; /* modification time (time_t) */
56-
public UInt32 crc; /* crc of file data */
57-
public Int16 comp_method; /* compression method used */
58-
public UInt16 encryption_method; /* encryption method used */
59-
public UInt32 flags; /* reserved for future use */
52+
public UInt64 valid; /* which fields have valid values */
53+
public IntPtr name; /* name of the file (char *) */
54+
public UInt64 index; /* index within archive */
55+
public UInt64 size; /* size of file (uncompressed) */
56+
public UInt64 comp_size; /* size of file (compressed) */
57+
public IntPtr mtime; /* modification time (time_t) */
58+
public UInt32 crc; /* crc of file data */
59+
public Int16 comp_method; /* compression method used */
60+
public UInt16 encryption_method; /* encryption method used */
61+
public UInt32 flags; /* reserved for future use */
6062
};
6163

6264
[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
@@ -360,7 +362,7 @@ public static int zip_set_file_comment (IntPtr archive, UInt64 index, string com
360362

361363
[DllImport (ZIP_LIBNAME, CallingConvention = CallingConvention.Cdecl)]
362364
public static extern int zip_set_file_compression (IntPtr archive, UInt64 index, CompressionMethod comp, UInt32 comp_flags);
363-
365+
364366
[DllImport (ZIP_LIBNAME, CallingConvention = CallingConvention.Cdecl)]
365367
public static extern int zip_file_set_mtime(IntPtr archive, UInt64 index, ulong mtime, UInt32 flags);
366368

0 commit comments

Comments
 (0)