Detect device paths which contain extra data

Apparently some firmware may add extra data to the device path,
so exit the loop on the first end-of-path record.
Fixes GH issue #181.
This commit is contained in:
Lauri Kenttä
2024-03-24 17:26:08 +02:00
parent 39596aadfc
commit 665a4732ca

View File

@@ -99,7 +99,13 @@ public class Efi {
if (len < 4 || pos + len > pathNodesEnd) { if (len < 4 || pos + len > pathNodesEnd) {
return; // throw new Exception("Bad entry."); return; // throw new Exception("Bad entry.");
} }
DevicePathNodes.Add(new DevicePathNode(data.Skip(pos).Take(len).ToArray())); var node = new DevicePathNode(data.Skip(pos).Take(len).ToArray());
DevicePathNodes.Add(node);
if (node.Type == 0x7f && node.SubType == 0xff) {
// End of entire device path.
// Apparently some firmwares produce paths with unused nodes at the end.
break;
}
pos += len; pos += len;
} }
Arguments = data.Skip(pathNodesEnd).ToArray(); Arguments = data.Skip(pathNodesEnd).ToArray();