Merge pull request #1655 from balena-os/vipul/fix-getcpuid

patch: Fix substring end parameter to get accurate CPU ID
This commit is contained in:
bulldozer-balena[bot] 2021-04-12 22:01:44 +00:00 committed by GitHub
commit 192589d19e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 2 deletions

View File

@ -69,7 +69,7 @@ export async function getCpuId(): Promise<string | undefined> {
try {
const buffer = await fs.readFile('/proc/device-tree/serial-number');
// Remove the null byte at the end
return buffer.toString('utf-8').substr(0, buffer.length - 2);
return buffer.toString('utf-8').replace(/\0/g, '');
} catch {
return undefined;
}

View File

@ -119,7 +119,7 @@ describe('System information', async () => {
]),
);
const cpuId = await sysInfo.getCpuId();
expect(cpuId).to.equal('1000000001b93f3');
expect(cpuId).to.equal('1000000001b93f3f');
fsStub.restore();
});
});