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

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

‎Native.cs‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
usingSystem;
2828
usingSystem.Runtime.InteropServices;
2929

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

4850
publicstructzip_stat_t
4951
{
50-
publicUInt64valid;/* which fields have valid values */
51-
publicIntPtrname;/* name of the file (char *) */
52-
publicUInt64index;/* index within archive */
53-
publicUInt64size;/* size of file (uncompressed) */
54-
publicUInt64comp_size;/* size of file (compressed) */
55-
publicIntPtrmtime;/* modification time (time_t) */
56-
publicUInt32crc;/* crc of file data */
57-
publicInt16comp_method;/* compression method used */
58-
publicUInt16encryption_method;/* encryption method used */
59-
publicUInt32flags;/* reserved for future use */
52+
publicUInt64valid;/* which fields have valid values */
53+
publicIntPtrname;/* name of the file (char *) */
54+
publicUInt64index;/* index within archive */
55+
publicUInt64size;/* size of file (uncompressed) */
56+
publicUInt64comp_size;/* size of file (compressed) */
57+
publicIntPtrmtime;/* modification time (time_t) */
58+
publicUInt32crc;/* crc of file data */
59+
publicInt16comp_method;/* compression method used */
60+
publicUInt16encryption_method;/* encryption method used */
61+
publicUInt32flags;/* 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
publicstaticexternintzip_set_file_compression(IntPtrarchive,UInt64index,CompressionMethodcomp,UInt32comp_flags);
363-
365+
364366
[DllImport(ZIP_LIBNAME,CallingConvention=CallingConvention.Cdecl)]
365367
publicstaticexternintzip_file_set_mtime(IntPtrarchive,UInt64index,ulongmtime,UInt32flags);
366368

0 commit comments

Comments
 (0)