Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameters for chown should be signed integers not unsigned #15828

Merged
merged 7 commits into from Jul 26, 2019
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 12 additions & 12 deletions mcs/class/Mono.Posix/Documentation/en/Mono.Unix.Native/Syscall.xml
Expand Up @@ -695,8 +695,8 @@
</Docs>
</Member>
<Member MemberName="chown">
<MemberSignature Language="C#" Value="public static int chown (string path, uint owner, uint group);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig pinvokeimpl (&quot;libc&quot; as &quot;chown&quot; winapi lasterr)int32 chown(string path, unsigned int32 owner, unsigned int32 group) cil managed" />
<MemberSignature Language="C#" Value="public static int chown (string path, int owner, int group);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig pinvokeimpl (&quot;libc&quot; as &quot;chown&quot; winapi lasterr)int32 chown(string path, int32 owner, int32 group) cil managed" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
Expand All @@ -708,8 +708,8 @@
</ReturnValue>
<Parameters>
<Parameter Name="path" Type="System.String" />
<Parameter Name="owner" Type="System.UInt32" />
<Parameter Name="group" Type="System.UInt32" />
<Parameter Name="owner" Type="System.Int32" />
<Parameter Name="group" Type="System.Int32" />
</Parameters>
<Docs>
<param name="path">To be added.</param>
Expand Down Expand Up @@ -1835,8 +1835,8 @@
</Docs>
</Member>
<Member MemberName="fchown">
<MemberSignature Language="C#" Value="public static int fchown (int fd, uint owner, uint group);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig pinvokeimpl (&quot;libc&quot; as &quot;fchown&quot; winapi lasterr)int32 fchown(int32 fd, unsigned int32 owner, unsigned int32 group) cil managed" />
<MemberSignature Language="C#" Value="public static int fchown (int fd, int owner, int group);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig pinvokeimpl (&quot;libc&quot; as &quot;fchown&quot; winapi lasterr)int32 fchown(int32 fd, int32 owner, int32 group) cil managed" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
Expand All @@ -1848,8 +1848,8 @@
</ReturnValue>
<Parameters>
<Parameter Name="fd" Type="System.Int32" />
<Parameter Name="owner" Type="System.UInt32" />
<Parameter Name="group" Type="System.UInt32" />
<Parameter Name="owner" Type="System.Int32" />
<Parameter Name="group" Type="System.Int32" />
</Parameters>
<Docs>
<param name="fd">To be added.</param>
Expand Down Expand Up @@ -4354,8 +4354,8 @@
</Docs>
</Member>
<Member MemberName="lchown">
<MemberSignature Language="C#" Value="public static int lchown (string path, uint owner, uint group);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig pinvokeimpl (&quot;libc&quot; as &quot;lchown&quot; winapi lasterr)int32 lchown(string path, unsigned int32 owner, unsigned int32 group) cil managed" />
<MemberSignature Language="C#" Value="public static int lchown (string path, int owner, int group);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig pinvokeimpl (&quot;libc&quot; as &quot;lchown&quot; winapi lasterr)int32 lchown(string path, int32 owner, int32 group) cil managed" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
Expand All @@ -4367,8 +4367,8 @@
</ReturnValue>
<Parameters>
<Parameter Name="path" Type="System.String" />
<Parameter Name="owner" Type="System.UInt32" />
<Parameter Name="group" Type="System.UInt32" />
<Parameter Name="owner" Type="System.Int32" />
<Parameter Name="group" Type="System.Int32" />
</Parameters>
<Docs>
<param name="path">To be added.</param>
Expand Down
41 changes: 37 additions & 4 deletions mcs/class/Mono.Posix/Mono.Unix.Native/Syscall.cs
Expand Up @@ -4576,19 +4576,37 @@ public static int pipe (int[] filedes)
[DllImport (LIBC, SetLastError=true)]
public static extern int chown (
[MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
string path, uint owner, uint group);
string path, int owner, int group);

// fchown(2)
// int fchown(int fd, uid_t owner, gid_t group);
[DllImport (LIBC, SetLastError=true)]
public static extern int fchown (int fd, uint owner, uint group);
public static extern int fchown (int fd, int owner, int group);

// lchown(2)
// int lchown(const char *path, uid_t owner, gid_t group);
[DllImport (LIBC, SetLastError=true)]
public static extern int lchown (
[MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
string path, uint owner, uint group);
string path, int owner, int group);

#region UInt32 overloads for initial incorrect implementation
[Obsolete("Use Int32 overload")]
[DllImport (LIBC, SetLastError=true)]
public static extern int chown (
[MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
string path, uint owner, uint group);

[Obsolete("Use Int32 overload")]
[DllImport (LIBC, SetLastError=true)]
public static extern int fchown (int fd, uint owner, uint group);

[Obsolete("Use Int32 overload")]
[DllImport (LIBC, SetLastError=true)]
public static extern int lchown (
[MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
string path, uint owner, uint group);
#endregion

[DllImport (LIBC, SetLastError=true)]
public static extern int chdir (
Expand Down Expand Up @@ -5161,13 +5179,28 @@ public static int faccessat (int dirfd, string pathname, AccessModes mode, AtFla
[DllImport (LIBC, SetLastError=true, EntryPoint="fchownat")]
private static extern int sys_fchownat (int dirfd,
[MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
string pathname, uint owner, uint group, int flags);
string pathname, int owner, int group, int flags);

public static int fchownat (int dirfd, string pathname, int owner, int group, AtFlags flags)
{
int _flags = NativeConvert.FromAtFlags (flags);
return sys_fchownat (dirfd, pathname, owner, group, _flags);
}

#region UInt32 overloads for initial incorrect implementation
[Obsolete("Use Int32 overload")]
[DllImport (LIBC, SetLastError=true, EntryPoint="fchownat")]
private static extern int sys_fchownat (int dirfd,
[MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
string pathname, uint owner, uint group, int flags);

[Obsolete("Use Int32 overload")]
public static int fchownat (int dirfd, string pathname, uint owner, uint group, AtFlags flags)
{
int _flags = NativeConvert.FromAtFlags (flags);
return sys_fchownat (dirfd, pathname, owner, group, _flags);
}
#endregion

[DllImport (LIBC, SetLastError=true, EntryPoint="linkat")]
private static extern int sys_linkat (int olddirfd,
Expand Down
4 changes: 2 additions & 2 deletions mcs/class/Mono.Posix/Mono.Unix/UnixFileSystemInfo.cs
Expand Up @@ -325,8 +325,8 @@ public void SetLength (long length)

public virtual void SetOwner (long owner, long group)
{
uint _owner = Convert.ToUInt32 (owner);
uint _group = Convert.ToUInt32 (group);
int _owner = Convert.ToInt32 (owner);
int _group = Convert.ToInt32 (group);
int r = Native.Syscall.chown (FullPath, _owner, _group);
UnixMarshal.ThrowExceptionForLastErrorIf (r);
}
Expand Down
2 changes: 1 addition & 1 deletion mcs/class/Mono.Posix/Mono.Unix/UnixStream.cs
Expand Up @@ -356,7 +356,7 @@ public void SetOwner (long user, long group)
AssertNotDisposed ();

int r = Native.Syscall.fchown (fileDescriptor,
Convert.ToUInt32 (user), Convert.ToUInt32 (group));
Convert.ToInt32 (user), Convert.ToInt32 (group));
UnixMarshal.ThrowExceptionForLastErrorIf (r);
}

Expand Down
2 changes: 1 addition & 1 deletion mcs/class/Mono.Posix/Mono.Unix/UnixSymbolicLinkInfo.cs
Expand Up @@ -94,7 +94,7 @@ public override void Delete ()

public override void SetOwner (long owner, long group)
{
int r = Native.Syscall.lchown (FullPath, Convert.ToUInt32 (owner), Convert.ToUInt32 (group));
int r = Native.Syscall.lchown (FullPath, Convert.ToInt32 (owner), Convert.ToInt32 (group));
UnixMarshal.ThrowExceptionForLastErrorIf (r);
}

Expand Down