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

Securing the array for ResourceMonitoring's method #5111

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.Shared.Pools;

Expand All @@ -22,7 +23,7 @@ internal interface IFileSystem
/// Get directory names on the filesystem based on the provided pattern.
/// </summary>
/// <returns>string.</returns>
string[] GetDirectoryNames(string directory, string pattern);
IReadOnlyCollection<string> GetDirectoryNames(string directory, string pattern);

/// <summary>
/// Reads content from the file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
Expand Down Expand Up @@ -230,7 +231,7 @@ public ulong GetAvailableMemoryInBytes()
public long GetMemoryUsageInBytesFromSlices(string pattern)
{
// In cgroup v2, we need to read memory usage from all slices, which are directories in /sys/fs/cgroup/*.slice.
string[] memoryUsageInBytesSlicesPath = _fileSystem.GetDirectoryNames("/sys/fs/cgroup/", pattern);
IReadOnlyCollection<string> memoryUsageInBytesSlicesPath = _fileSystem.GetDirectoryNames("/sys/fs/cgroup/", pattern);

long memoryUsageInBytesTotal = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
Expand All @@ -22,7 +23,7 @@ public bool Exists(FileInfo fileInfo)
return fileInfo.Exists;
}

public string[] GetDirectoryNames(string directory, string pattern)
public IReadOnlyCollection<string> GetDirectoryNames(string directory, string pattern)
{
return Directory.GetDirectories(directory, pattern)
.ToArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Buffers;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Shared.Pools;
Expand All @@ -17,7 +18,7 @@ public bool Exists(FileInfo fileInfo)
return fileInfo.Exists;
}

public string[] GetDirectoryNames(string directory, string pattern)
public IReadOnlyCollection<string> GetDirectoryNames(string directory, string pattern)
{
throw new NotSupportedException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public bool Exists(FileInfo fileInfo)
return _fileContent.ContainsKey(fileInfo.FullName);
}

public string[] GetDirectoryNames(string directory, string pattern)
public IReadOnlyCollection<string> GetDirectoryNames(string directory, string pattern)
{
return _fileContent.Keys
.Where(x => x.StartsWith(directory, StringComparison.OrdinalIgnoreCase))
Expand Down