Skip to content

Commit af0f5fa

Browse files
authored
Merge pull request #662 from snyk/feat/add-ndb-rpm-support
feat: add support for NDB RPM database
2 parents 80242c4 + 628a240 commit af0f5fa

6 files changed

Lines changed: 2287 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: 36 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,37 @@ export async function getRpmSqliteDbFileContent(
6165
}
6266
}
6367

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

0 commit comments

Comments
 (0)