detect-libc
Advanced tools
Comparing version 2.0.1 to 2.0.2
@@ -0,1 +1,4 @@ | ||
// Copyright 2017 Lovell Fuller and others. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
export const GLIBC: 'glibc'; | ||
@@ -2,0 +5,0 @@ export const MUSL: 'musl'; |
@@ -0,1 +1,4 @@ | ||
// Copyright 2017 Lovell Fuller and others. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
'use strict'; | ||
@@ -5,3 +8,7 @@ | ||
const { isLinux, getReport } = require('./process'); | ||
const { LDD_PATH, readFile, readFileSync } = require('./filesystem'); | ||
let cachedFamilyFilesystem; | ||
let cachedVersionFilesystem; | ||
const command = 'getconf GNU_LIBC_VERSION 2>&1 || true; ldd --version 2>&1 || true'; | ||
@@ -41,2 +48,8 @@ let commandOut = ''; | ||
/** | ||
* A Regexp constant to get the GLIBC Version. | ||
* @type {string} | ||
*/ | ||
const RE_GLIBC_VERSION = /GLIBC\s(\d+\.\d+)/; | ||
/** | ||
* A String constant containing the value `musl`. | ||
@@ -48,2 +61,14 @@ * @type {string} | ||
/** | ||
* This string is used to find if the {@link LDD_PATH} is GLIBC | ||
* @type {string} | ||
*/ | ||
const GLIBC_ON_LDD = GLIBC.toUpperCase(); | ||
/** | ||
* This string is used to find if the {@link LDD_PATH} is musl | ||
* @type {string} | ||
*/ | ||
const MUSL_ON_LDD = MUSL.toLowerCase(); | ||
const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-'); | ||
@@ -75,2 +100,36 @@ | ||
const getFamilyFromLddContent = (content) => { | ||
if (content.includes(MUSL_ON_LDD)) { | ||
return MUSL; | ||
} | ||
if (content.includes(GLIBC_ON_LDD)) { | ||
return GLIBC; | ||
} | ||
return null; | ||
}; | ||
const familyFromFilesystem = async () => { | ||
if (cachedFamilyFilesystem !== undefined) { | ||
return cachedFamilyFilesystem; | ||
} | ||
cachedFamilyFilesystem = null; | ||
try { | ||
const lddContent = await readFile(LDD_PATH); | ||
cachedFamilyFilesystem = getFamilyFromLddContent(lddContent); | ||
} catch (e) {} | ||
return cachedFamilyFilesystem; | ||
}; | ||
const familyFromFilesystemSync = () => { | ||
if (cachedFamilyFilesystem !== undefined) { | ||
return cachedFamilyFilesystem; | ||
} | ||
cachedFamilyFilesystem = null; | ||
try { | ||
const lddContent = readFileSync(LDD_PATH); | ||
cachedFamilyFilesystem = getFamilyFromLddContent(lddContent); | ||
} catch (e) {} | ||
return cachedFamilyFilesystem; | ||
}; | ||
/** | ||
@@ -83,4 +142,7 @@ * Resolves with the libc family when it can be determined, `null` otherwise. | ||
if (isLinux()) { | ||
family = familyFromReport(); | ||
family = await familyFromFilesystem(); | ||
if (!family) { | ||
family = familyFromReport(); | ||
} | ||
if (!family) { | ||
const out = await safeCommand(); | ||
@@ -100,4 +162,7 @@ family = familyFromCommand(out); | ||
if (isLinux()) { | ||
family = familyFromReport(); | ||
family = familyFromFilesystemSync(); | ||
if (!family) { | ||
family = familyFromReport(); | ||
} | ||
if (!family) { | ||
const out = safeCommandSync(); | ||
@@ -122,2 +187,32 @@ family = familyFromCommand(out); | ||
const versionFromFilesystem = async () => { | ||
if (cachedVersionFilesystem !== undefined) { | ||
return cachedVersionFilesystem; | ||
} | ||
cachedVersionFilesystem = null; | ||
try { | ||
const lddContent = await readFile(LDD_PATH); | ||
const versionMatch = lddContent.match(RE_GLIBC_VERSION); | ||
if (versionMatch) { | ||
cachedVersionFilesystem = versionMatch[1]; | ||
} | ||
} catch (e) {} | ||
return cachedVersionFilesystem; | ||
}; | ||
const versionFromFilesystemSync = () => { | ||
if (cachedVersionFilesystem !== undefined) { | ||
return cachedVersionFilesystem; | ||
} | ||
cachedVersionFilesystem = null; | ||
try { | ||
const lddContent = readFileSync(LDD_PATH); | ||
const versionMatch = lddContent.match(RE_GLIBC_VERSION); | ||
if (versionMatch) { | ||
cachedVersionFilesystem = versionMatch[1]; | ||
} | ||
} catch (e) {} | ||
return cachedVersionFilesystem; | ||
}; | ||
const versionFromReport = () => { | ||
@@ -151,4 +246,7 @@ const report = getReport(); | ||
if (isLinux()) { | ||
version = versionFromReport(); | ||
version = await versionFromFilesystem(); | ||
if (!version) { | ||
version = versionFromReport(); | ||
} | ||
if (!version) { | ||
const out = await safeCommand(); | ||
@@ -168,4 +266,7 @@ version = versionFromCommand(out); | ||
if (isLinux()) { | ||
version = versionFromReport(); | ||
version = versionFromFilesystemSync(); | ||
if (!version) { | ||
version = versionFromReport(); | ||
} | ||
if (!version) { | ||
const out = safeCommandSync(); | ||
@@ -172,0 +273,0 @@ version = versionFromCommand(out); |
@@ -0,1 +1,4 @@ | ||
// Copyright 2017 Lovell Fuller and others. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
'use strict'; | ||
@@ -2,0 +5,0 @@ |
{ | ||
"name": "detect-libc", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "Node.js module to detect the C standard library (libc) implementation family and version", | ||
@@ -11,3 +11,5 @@ "main": "lib/detect-libc.js", | ||
"scripts": { | ||
"test": "semistandard && nyc --reporter=lcov --check-coverage --branches=100 ava test/unit.js" | ||
"test": "semistandard && nyc --reporter=lcov --check-coverage --branches=100 ava test/unit.js", | ||
"bench": "node benchmark/detect-libc", | ||
"bench:calls": "node benchmark/call-familySync.js && sleep 1 && node benchmark/call-isNonGlibcLinuxSync.js && sleep 1 && node benchmark/call-versionSync.js" | ||
}, | ||
@@ -25,3 +27,4 @@ "repository": { | ||
"contributors": [ | ||
"Niklas Salmoukas <niklas@salmoukas.com>" | ||
"Niklas Salmoukas <niklas@salmoukas.com>", | ||
"Vinícius Lourenço <vinyygamerlol@gmail.com>" | ||
], | ||
@@ -31,2 +34,3 @@ "license": "Apache-2.0", | ||
"ava": "^2.4.0", | ||
"benchmark": "^2.1.4", | ||
"nyc": "^15.1.0", | ||
@@ -33,0 +37,0 @@ "proxyquire": "^2.1.3", |
@@ -11,2 +11,5 @@ # detect-libc | ||
The version numbers of libc implementations | ||
are not guaranteed to be semver-compliant. | ||
For previous v1.x releases, please see the | ||
@@ -151,3 +154,3 @@ [v1](https://github.com/lovell/detect-libc/tree/v1) branch. | ||
Copyright 2017, 2022 Lovell Fuller | ||
Copyright 2017 Lovell Fuller and others. | ||
@@ -154,0 +157,0 @@ Licensed under the Apache License, Version 2.0 (the "License"); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23709
7
310
164
5
1