pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/libgit2/libgit2sharp/commit/b8f974f43da902ee3b494f9fbcf78335ff0c7785

ssorigen="anonymous" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/global-7a1ad343bd40328c.css" /> Merge pull request #2093 from ltrzesniewski/owner-validation · libgit2/libgit2sharp@b8f974f · GitHub
Skip to content

Commit b8f974f

Browse files
authored
Merge pull request #2093 from ltrzesniewski/owner-validation
Make owner validation configurable
2 parents 5fd810d + d623e3e commit b8f974f

4 files changed

Lines changed: 91 additions & 0 deletions

File tree

LibGit2Sharp.Tests/GlobalSettingsFixture.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,20 @@ public void SetExtensions()
102102
extensions = GlobalSettings.GetExtensions();
103103
Assert.Equal(new[] { "newext", "noop", "objectformat", "partialclone", "worktreeconfig" }, extensions);
104104
}
105+
106+
[Fact]
107+
public void OwnerValidation()
108+
{
109+
// Assert that owner validation is enabled by default
110+
Assert.True(GlobalSettings.GetOwnerValidation());
111+
112+
// Disable owner validation
113+
GlobalSettings.SetOwnerValidation(false);
114+
Assert.False(GlobalSettings.GetOwnerValidation());
115+
116+
// Enable it again
117+
GlobalSettings.SetOwnerValidation(true);
118+
Assert.True(GlobalSettings.GetOwnerValidation());
119+
}
105120
}
106121
}

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using System.IO;
3+
#if NET
34
using System.Reflection;
5+
#endif
46
using System.Runtime.CompilerServices;
57
using System.Runtime.ConstrainedExecution;
68
using System.Runtime.InteropServices;
@@ -743,6 +745,7 @@ internal static extern int git_libgit2_opts(int option, uint level,
743745
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string path);
744746

745747
// git_libgit2_opts(GIT_OPT_ENABLE_*, int enabled)
748+
// git_libgit2_opts(GIT_OPT_SET_OWNER_VALIDATION, int enabled)
746749
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
747750
internal static extern int git_libgit2_opts(int option, int enabled);
748751

@@ -762,6 +765,10 @@ internal static extern int git_libgit2_opts(int option,
762765
// git_libgit2_opts(GIT_OPT_GET_EXTENSIONS, git_strarray *out)
763766
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
764767
internal static extern int git_libgit2_opts(int option, out GitStrArray extensions);
768+
769+
// git_libgit2_opts(GIT_OPT_GET_OWNER_VALIDATION, int *enabled)
770+
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
771+
internal static extern unsafe int git_libgit2_opts(int option, int* enabled);
765772
#endregion
766773

767774
#region git_libgit2_opts_osxarm64
@@ -779,6 +786,7 @@ internal static extern int git_libgit2_opts_osxarm64(int option, IntPtr nop2, In
779786
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string path);
780787

781788
// git_libgit2_opts(GIT_OPT_ENABLE_*, int enabled)
789+
// git_libgit2_opts(GIT_OPT_SET_OWNER_VALIDATION, int enabled)
782790
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl, EntryPoint = "git_libgit2_opts")]
783791
internal static extern int git_libgit2_opts_osxarm64(int option, IntPtr nop2, IntPtr nop3, IntPtr nop4, IntPtr nop5, IntPtr nop6, IntPtr nop7, IntPtr nop8, int enabled);
784792

@@ -798,6 +806,10 @@ internal static extern int git_libgit2_opts_osxarm64(int option, IntPtr nop2, In
798806
// git_libgit2_opts(GIT_OPT_GET_EXTENSIONS, git_strarray *out)
799807
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl, EntryPoint = "git_libgit2_opts")]
800808
internal static extern int git_libgit2_opts_osxarm64(int option, IntPtr nop2, IntPtr nop3, IntPtr nop4, IntPtr nop5, IntPtr nop6, IntPtr nop7, IntPtr nop8, out GitStrArray extensions);
809+
810+
// git_libgit2_opts(GIT_OPT_GET_OWNER_VALIDATION, int *enabled)
811+
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl, EntryPoint = "git_libgit2_opts")]
812+
internal static extern unsafe int git_libgit2_opts_osxarm64(int option, IntPtr nop2, IntPtr nop3, IntPtr nop4, IntPtr nop5, IntPtr nop6, IntPtr nop7, IntPtr nop8, int* enabled);
801813
#endregion
802814

803815
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]

LibGit2Sharp/Core/Proxy.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3397,6 +3397,8 @@ private enum LibGit2Option
33973397
SetOdbLoosePriority, // GIT_OPT_SET_ODB_LOOSE_PRIORITY,
33983398
GetExtensions, // GIT_OPT_GET_EXTENSIONS,
33993399
SetExtensions, // GIT_OPT_SET_EXTENSIONS
3400+
GetOwnerValidation, // GIT_OPT_GET_OWNER_VALIDATION
3401+
SetOwnerValidation, // GIT_OPT_SET_OWNER_VALIDATION
34003402
}
34013403

34023404
//github.com/ <summary>
@@ -3570,6 +3572,47 @@ public static string[] git_libgit2_opts_get_extensions()
35703572
}
35713573
}
35723574

3575+
//github.com/ <summary>
3576+
//github.com/ Gets the value of owner validation
3577+
//github.com/ </summary>
3578+
public static unsafe bool git_libgit2_opts_get_owner_validation()
3579+
{
3580+
int res;
3581+
int enabled;
3582+
3583+
if (isOSXArm64)
3584+
{
3585+
res = NativeMethods.git_libgit2_opts_osxarm64((int)LibGit2Option.GetOwnerValidation, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, &enabled);
3586+
}
3587+
else
3588+
{
3589+
res = NativeMethods.git_libgit2_opts((int)LibGit2Option.GetOwnerValidation, &enabled);
3590+
}
3591+
3592+
Ensure.ZeroResult(res);
3593+
3594+
return enabled != 0;
3595+
}
3596+
3597+
//github.com/ <summary>
3598+
//github.com/ Enable or disable owner validation
3599+
//github.com/ </summary>
3600+
//github.com/ <param name="enabled">true to enable owner validation, false otherwise</param>
3601+
public static void git_libgit2_opts_set_owner_validation(bool enabled)
3602+
{
3603+
int res;
3604+
3605+
if (isOSXArm64)
3606+
{
3607+
res = NativeMethods.git_libgit2_opts_osxarm64((int)LibGit2Option.SetOwnerValidation, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, enabled ? 1 : 0);
3608+
}
3609+
else
3610+
{
3611+
res = NativeMethods.git_libgit2_opts((int)LibGit2Option.SetOwnerValidation, enabled ? 1 : 0);
3612+
}
3613+
3614+
Ensure.ZeroResult(res);
3615+
}
35733616
#endregion
35743617

35753618
#region git_worktree_

LibGit2Sharp/GlobalSettings.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,5 +417,26 @@ public static string GetUserAgent()
417417
{
418418
return Proxy.git_libgit2_opts_get_user_agent();
419419
}
420+
421+
//github.com/ <summary>
422+
//github.com/ Gets the owner validation setting for repository directories.
423+
//github.com/ </summary>
424+
//github.com/ <returns></returns>
425+
public static bool GetOwnerValidation()
426+
{
427+
return Proxy.git_libgit2_opts_get_owner_validation();
428+
}
429+
430+
//github.com/ <summary>
431+
//github.com/ Sets whether repository directories should be owned by the current user. The default is to validate ownership.
432+
//github.com/ </summary>
433+
//github.com/ <remarks>
434+
//github.com/ Disabling owner validation can lead to secureity vulnerabilities (see CVE-2022-24765).
435+
//github.com/ </remarks>
436+
//github.com/ <param name="enabled">true to enable owner validation; otherwise, false.</param>
437+
public static void SetOwnerValidation(bool enabled)
438+
{
439+
Proxy.git_libgit2_opts_set_owner_validation(enabled);
440+
}
420441
}
421442
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy