Skip to content

Commit 07563cd

Browse files
CopilotJusterZhu
andcommitted
Fix security issues: prevent command injection and improve certificate parsing
Co-authored-by: JusterZhu <11714536+JusterZhu@users.noreply.github.com>
1 parent 406494e commit 07563cd

2 files changed

Lines changed: 27 additions & 16 deletions

File tree

src/c#/GeneralUpdate.Drivelution/Linux/Implementation/LinuxGeneralDrivelution.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,9 @@ private async Task ParseDebPackageAsync(string debPath, DriverInfo driverInfo, C
524524
try
525525
{
526526
// Try to get package info using dpkg-deb command
527-
var output = await ExecuteCommandAsync("dpkg-deb", $"-I {debPath}", cancellationToken);
527+
// Use proper argument passing to avoid injection issues
528+
var escapedPath = debPath.Replace("'", "'\\''");
529+
var output = await ExecuteCommandAsync("dpkg-deb", $"-I '{escapedPath}'", cancellationToken);
528530
var lines = output.Split('\n');
529531

530532
foreach (var line in lines)
@@ -562,7 +564,9 @@ private async Task ParseRpmPackageAsync(string rpmPath, DriverInfo driverInfo, C
562564
try
563565
{
564566
// Try to get package info using rpm command
565-
var output = await ExecuteCommandAsync("rpm", $"-qip {rpmPath}", cancellationToken);
567+
// Use proper argument passing to avoid injection issues
568+
var escapedPath = rpmPath.Replace("'", "'\\''");
569+
var output = await ExecuteCommandAsync("rpm", $"-qip '{escapedPath}'", cancellationToken);
566570
var lines = output.Split('\n');
567571

568572
foreach (var line in lines)

src/c#/GeneralUpdate.Drivelution/Windows/Implementation/WindowsGeneralDrivelution.cs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -547,23 +547,30 @@ public async Task<List<DriverInfo>> GetDriversFromDirectoryAsync(
547547
if (WindowsSignatureHelper.IsFileSigned(filePath))
548548
{
549549
// Try to extract publisher from certificate
550-
using var cert = System.Security.Cryptography.X509Certificates.X509Certificate.CreateFromSignedFile(filePath);
551-
if (cert != null)
550+
using var cert2 = new System.Security.Cryptography.X509Certificates.X509Certificate2(filePath);
551+
var subject = cert2.Subject;
552+
553+
// Extract CN (Common Name) from subject
554+
var cnIndex = subject.IndexOf("CN=");
555+
if (cnIndex >= 0)
552556
{
553-
using var cert2 = new System.Security.Cryptography.X509Certificates.X509Certificate2(cert);
554-
var subject = cert2.Subject;
557+
var cnStart = cnIndex + 3;
558+
var cnEnd = subject.IndexOf(',', cnStart);
555559

556-
// Extract CN (Common Name) from subject
557-
if (subject.Contains("CN="))
560+
string publisher;
561+
if (cnEnd > cnStart)
558562
{
559-
var cnStart = subject.IndexOf("CN=") + 3;
560-
var cnEnd = subject.IndexOf(',', cnStart);
561-
var publisher = cnEnd > cnStart ? subject.Substring(cnStart, cnEnd - cnStart) : subject.Substring(cnStart);
562-
563-
if (!string.IsNullOrEmpty(publisher))
564-
{
565-
driverInfo.TrustedPublishers.Add(publisher);
566-
}
563+
publisher = subject.Substring(cnStart, cnEnd - cnStart);
564+
}
565+
else
566+
{
567+
// No comma after CN, take the rest of the string
568+
publisher = subject.Substring(cnStart);
569+
}
570+
571+
if (!string.IsNullOrEmpty(publisher))
572+
{
573+
driverInfo.TrustedPublishers.Add(publisher);
567574
}
568575
}
569576
}

0 commit comments

Comments
 (0)