jantari / LSUClient

Orchestrate driver, BIOS/UEFI and firmware updates for Lenovo computers šŸ‘Øā€šŸ’»
https://jantari.github.io/LSUClient-docs/
MIT License
208 stars 22 forks source link

Severity and SeverityOverride don't pass validation in Resolve-XMLDependencies #63

Closed animentork closed 1 year ago

animentork commented 1 year ago

Version

1.5.0

Computer Model

all

Problem

This line in Get-LSUpdate.ps1 produces an error with some drivers: if (Resolve-XMLDependencies -XMLIN $packageXML.Package.SeverityOverride -TreatUnsupportedAsPassed:$true -PackagePath $LocalPackageRoot -FailInboxDrivers) {

Error: PS>TerminatingError(Resolve-XMLDependencies): "Cannot validate argument on parameter 'XMLIN'. The argument is null, empty, or an element of the argument collection contains a null value. Supply a collection that does not contain any null values and then try the command again."

Steps to reproduce:

Here is a shortened example of such a driver XML file, save it as j5ia09ww2.xml:

<?xml version="1.0" encoding="utf-8"?>
<?pcdDescriptor version="0230"?>
<Package name="CHIPSET_J5IA" id="j5ia09ww" version="10.1.3.1" hide="False">
  <Title default="EN">
    <Desc id="EN">Intel(R) Chipset Device Software - 10 [64]</Desc>
  </Title>
  <DetectVersion type="Inf">
    <_PnPID><![CDATA[PCI\VEN_8086&DEV_1604]]></_PnPID>
  </DetectVersion>
  <Summary default="EN" />
  <Severity type="1" />
  <SeverityOverride type="2" />
</Package>

Define the following test function:

function Test {
    param(
    [ValidateNotNullOrEmpty()]
    $XMLIN
    )
    Write-Host "no error if you see this"
}

You can provoke the error as follows:

$rawPackageXML = Get-Content -Path "j5ia09ww_2_.xml"
[xml]$packageXML = $rawPackageXML -replace "^$UTF8ByteOrderMark"
Test -XMLIN $packageXML.Package.SeverityOverride

Error: PS>TerminatingError(Resolve-XMLDependencies): "Cannot validate argument on parameter 'XMLIN'. The argument is null, empty, or an element of the argument collection contains a null value. Supply a collection that does not contain any null values and then try the command again."

Cause:

I think it's because Severity and SeverityOverride are always "empty" from PowerShell's perspective. It has an XML attribute:

$packageXML.Package.SeverityOverride

type
----
2

But it's empty:

$packageXML.Package.SeverityOverride.IsEmpty
True

I think that's why the validation in the parameters of Resolve-XMLDependencies raises the error!

Additional context

No response

jantari commented 1 year ago

Thanks for reporting this and you are absolutely correct. The fact that the SeverityOverride exists in this package but doesn't contain any child nodes caused the error. I was able to reproduce this with Get-LSUpdate -Model 20DT for example.

I've pushed fa5e1ff to the develop branch which fixes this and will be included in the next release of LSUClient, likely 1.5.1

animentork commented 1 year ago

Great, thanks! Do you know if those XML elements ever contain any child nodes? I thought they only have their type attributes. If there were never any child nodes, the if statement would never be true.

jantari commented 1 year ago

Yes, in fact SeverityOverride is usually either missing entirely or contains child nodes defining the tests for when the override is supposed to be applied like in this Intel Bluetooth Driver:

<Severity type="1"/>
<SeverityOverride type="2">
  <Not>
    <_Driver>
      <HardwareID>
        <![CDATA[ USB\VID_8087&PID_0029 ]]>
      </HardwareID>
      <Version>0.1^</Version>
    </_Driver>
  </Not>
</SeverityOverride>

The case you have found here where it exists, has a type defined, but is otherwise empty must be fairly rare as this is the first time this error has been reported. It's possibly even a one-off mistake / broken package on Lenovos part.

That being said, there's also plenty of packages where the "base-Severity" is identical to the SeverityOverride, like in this Synaptics FingerPrint driver:

<Severity type="2"/>
<SeverityOverride type="2">
  <Not>
    <_Driver>
      <HardwareID>
        <![CDATA[ USB\VID_06CB&PID_00BD ]]>
      </HardwareID>
      <HardwareID>
        <![CDATA[ USB\VID_06CB&PID_00C2 ]]>
      </HardwareID>
      <HardwareID>
        <![CDATA[ USB\VID_06CB&PID_0123 ]]>
      </HardwareID>
      <Version>0.1^</Version>
    </_Driver>
  </Not>
</SeverityOverride>

which also doesn't quite make sense to me, so it's entirely possible I've been misinterpreting the meaning of Severity vs SeverityOverride. But I don't have a better guess yet šŸ˜…

jantari commented 1 year ago

Published Version 1.5.1 which includes this fix