Skip to content

Commit 37e3bf7

Browse files
committed
Fix bug: pipe names could be read past their end.
1 parent 0ef1b12 commit 37e3bf7

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

Native.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ public static IEnumerable<PipeModel> GetPipes(string pipeHost = ".")
142142
FILE_DIRECTORY_INFORMATION fdi = PtrToStruct<FILE_DIRECTORY_INFORMATION>(tmp);
143143
IntPtr namePtr = (IntPtr)(FILE_DIRECTORY_INFORMATION.FileNameOffset + tmp.ToInt64());
144144

145-
yield return new PipeModel(pipeHost, Marshal.PtrToStringUni(namePtr), (int)fdi.AllocationSize.LowPart, fdi.EndOfFile.LowPart, null /* TODO */);
145+
// fdi.FileNameLength/2 - because FileNameLength is in bytes
146+
yield return new PipeModel(pipeHost, Marshal.PtrToStringUni(namePtr, (int)fdi.FileNameLength/2), (int)fdi.AllocationSize.LowPart, fdi.EndOfFile.LowPart, null /* TODO */);
146147

147148
if (fdi.NextEntryOffset == 0)
148149
break;

0 commit comments

Comments
 (0)