Skip to content
This repository was archived by the owner on Jan 21, 2021. It is now read-only.

Commit dc1a5e5

Browse files
author
mattifestation
committed
Add-Persistence bugfix
When file paths were specified, they were not being properly validated.
1 parent 956e4c9 commit dc1a5e5

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

Persistence/Persistence.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
ModuleToProcess = 'Persistence.psm1'
55

66
# Version number of this module.
7-
ModuleVersion = '1.1.0.0'
7+
ModuleVersion = '1.1.1.0'
88

99
# ID used to uniquely identify this module
1010
GUID = '633d0f10-a056-41da-869d-6d2f75430195'

Persistence/Persistence.psm1

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -417,11 +417,9 @@ function Add-Persistence
417417
[String]
418418
$PersistenceScriptName = 'Update-Windows',
419419

420-
[ValidateNotNullOrEmpty()]
421420
[String]
422421
$PersistentScriptFilePath = "$PWD\Persistence.ps1",
423422

424-
[ValidateNotNullOrEmpty()]
425423
[String]
426424
$RemovalScriptFilePath = "$PWD\RemovePersistence.ps1",
427425

@@ -446,35 +444,49 @@ function Add-Persistence
446444
throw 'You provided invalid user-level persistence options.'
447445
}
448446

449-
$Path = Split-Path $PersistentScriptFilePath -ErrorAction Stop
447+
$Result = Get-Item $PersistentScriptFilePath -ErrorAction SilentlyContinue
448+
if ($Result -and $Result.PSIsContainer)
449+
{
450+
throw 'You must provide a file name with the PersistentScriptFilePath option.'
451+
}
452+
453+
$Result = Get-Item $RemovalScriptFilePath -ErrorAction SilentlyContinue
454+
if ($Result -and $Result.PSIsContainer)
455+
{
456+
throw 'You must provide a file name with the RemovalScriptFilePath option.'
457+
}
458+
459+
$PersistentPath = Split-Path $PersistentScriptFilePath -ErrorAction Stop
450460
$Leaf = Split-Path $PersistentScriptFilePath -Leaf -ErrorAction Stop
451461
$PersistentScriptFile = ''
452462
$RemovalScriptFile = ''
453463

454-
if ($Path -eq '')
464+
if ($PersistentPath -eq '')
455465
{
466+
# i.e. Only a file name was provided implying $PWD
456467
$PersistentScriptFile = "$($PWD)\$($Leaf)"
457468
}
458469
else
459470
{
460-
$PersistentScriptFile = "$($Path)\$($Leaf)"
471+
$PersistentScriptFile = "$(Resolve-Path $PersistentPath)\$($Leaf)"
461472
}
462473

463-
$Path = Split-Path $RemovalScriptFilePath -ErrorAction Stop
474+
$RemovalPath = Split-Path $RemovalScriptFilePath -ErrorAction Stop
464475
$Leaf = Split-Path $RemovalScriptFilePath -Leaf -ErrorAction Stop
465-
if ($Path -eq '')
476+
if ($RemovalPath -eq '')
466477
{
478+
# i.e. Only a file name was provided implying $PWD
467479
$RemovalScriptFile = "$($PWD)\$($Leaf)"
468480
}
469481
else
470482
{
471-
$RemovalScriptFile = "$($Path)\$($Leaf)"
483+
$RemovalScriptFile = "$(Resolve-Path $RemovalPath)\$($Leaf)"
472484
}
473485

474486
if ($PSBoundParameters['FilePath'])
475487
{
476-
Get-ChildItem $FilePath -ErrorAction Stop
477-
$Script = [IO.File]::ReadAllText((Resolve-Path $Path))
488+
$null = Get-ChildItem $FilePath -ErrorAction Stop
489+
$Script = [IO.File]::ReadAllText((Resolve-Path $FilePath))
478490
}
479491
else
480492
{

0 commit comments

Comments
 (0)