Skip to content

Commit dcb4c1b

Browse files
committed
feat: add support for NDB RPM database used in SLE15.2+ CN-70
1 parent bce585b commit dcb4c1b

8 files changed

Lines changed: 2358 additions & 24 deletions

File tree

lib/analyzer/static-analyzer.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ import {
4444
import {
4545
getRpmDbFileContent,
4646
getRpmDbFileContentAction,
47+
getRpmNdbFileContent,
48+
getRpmNdbFileContentAction,
4749
getRpmSqliteDbFileContent,
4850
getRpmSqliteDbFileContentAction,
4951
} from "../inputs/rpm/static";
@@ -90,6 +92,7 @@ export async function analyze(
9092
getExtFileContentAction,
9193
getRpmDbFileContentAction,
9294
getRpmSqliteDbFileContentAction,
95+
getRpmNdbFileContentAction,
9396
...getOsReleaseActions,
9497
getNodeBinariesFileContentAction,
9598
getOpenJDKBinariesFileContentAction,
@@ -153,11 +156,13 @@ export async function analyze(
153156
aptDbFileContent,
154157
rpmDbFileContent,
155158
rpmSqliteDbFileContent,
159+
rpmNdbFileContent,
156160
] = await Promise.all([
157161
getApkDbFileContent(extractedLayers),
158162
getAptDbFileContent(extractedLayers),
159163
getRpmDbFileContent(extractedLayers),
160164
getRpmSqliteDbFileContent(extractedLayers),
165+
getRpmNdbFileContent(extractedLayers),
161166
]);
162167

163168
const distrolessAptFiles = getAptFiles(extractedLayers);
@@ -187,7 +192,12 @@ export async function analyze(
187192
results = await Promise.all([
188193
apkAnalyze(targetImage, apkDbFileContent),
189194
aptAnalyze(targetImage, aptDbFileContent, osRelease),
190-
rpmAnalyze(targetImage, rpmDbFileContent, redHatRepositories, osRelease),
195+
rpmAnalyze(
196+
targetImage,
197+
[...rpmDbFileContent, ...rpmNdbFileContent],
198+
redHatRepositories,
199+
osRelease,
200+
),
191201
mapRpmSqlitePackages(
192202
targetImage,
193203
rpmSqliteDbFileContent,

lib/inputs/rpm/static.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { getPackages, getPackagesSqlite } from "@snyk/rpm-parser";
1+
import {
2+
getPackages,
3+
getPackagesNdb,
4+
getPackagesSqlite,
5+
} from "@snyk/rpm-parser";
26
import { PackageInfo } from "@snyk/rpm-parser/lib/rpm/types";
37
import { Response } from "@snyk/rpm-parser/lib/types";
48
import * as Debug from "debug";
@@ -61,6 +65,38 @@ export async function getRpmSqliteDbFileContent(
6165
}
6266
}
6367

68+
export const getRpmNdbFileContentAction: ExtractAction = {
69+
actionName: "rpm-ndb",
70+
filePathMatches: (filePath) =>
71+
filePath === normalizePath("/var/lib/rpm/Packages.db") ||
72+
filePath === normalizePath("/usr/lib/sysimage/rpm/Packages.db"),
73+
callback: streamToBuffer,
74+
};
75+
76+
export async function getRpmNdbFileContent(
77+
extractedLayers: ExtractedLayers,
78+
): Promise<PackageInfo[]> {
79+
const rpmDb = getContentAsBuffer(extractedLayers, getRpmNdbFileContentAction);
80+
if (!rpmDb) {
81+
return [];
82+
}
83+
84+
try {
85+
const results: Response = await getPackagesNdb(rpmDb);
86+
87+
if (results.error) {
88+
throw results.error;
89+
}
90+
return results.response;
91+
} catch (error) {
92+
debug(
93+
`An error occurred while analysing RPM NDB packages:`,
94+
error.stack || error,
95+
);
96+
return [];
97+
}
98+
}
99+
64100
export const getRpmSqliteDbFileContentAction: ExtractAction = {
65101
actionName: "rpm-sqlite-db",
66102
filePathMatches: (filePath) =>

package-lock.json

Lines changed: 19 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"@snyk/composer-lockfile-parser": "^1.4.1",
3232
"@snyk/dep-graph": "^2.8.1",
3333
"@snyk/docker-registry-v2-client": "^2.15.0",
34-
"@snyk/rpm-parser": "^3.1.0",
34+
"@snyk/rpm-parser": "^3.3.0",
3535
"@snyk/snyk-docker-pull": "^3.14.2",
3636
"@swimlane/docker-reference": "^2.0.1",
3737
"adm-zip": "^0.5.16",

0 commit comments

Comments
 (0)