mirror of
https://github.com/morluto/rea.git
synced 2026-11-18 20:53:00 +00:00
fix(audit): report GCC profile paths retained in Go build flags (#12029)
Co-authored-by: ShuaixinHuang <197200901+ShuaixinHuang@users.noreply.github.com>
This commit is contained in:
1 parent
754589d4bf
commit
180e97f86f
2 files changed
+30
-2
No files matched your search
@@ -2239,6 +2239,32 @@ describe("ReleaseExposureService compiler path separators", () => {
|
||||
);
|
||||
});
|
||||
|
||||
describe("ReleaseExposureService compiler profile paths", () => {
|
||||
it.each([
|
||||
["CGO_CFLAGS", "-O2 -fprofile-use=internal/profiles", "internal/profiles"],
|
||||
["CGO_CFLAGS", "'-fprofile-dir=private profiles'", "private profiles"],
|
||||
["-ldflags", "-extldflags=-fprofile-generate=private/gcov", "private/gcov"],
|
||||
])("reports the named directory in %s %s", async (key, value, path) => {
|
||||
const report = await goReport(goModule([{ key, value }]));
|
||||
const check = report.checks.find((item) => item.id === "go.build_paths");
|
||||
expect(check?.status).toBe("exposed");
|
||||
expect(check?.observation.samples).toEqual([path]);
|
||||
});
|
||||
|
||||
it("finds no profile path for options without directory operands", async () => {
|
||||
const report = await goReport(
|
||||
goModule([
|
||||
{
|
||||
key: "CGO_CFLAGS",
|
||||
value: "-fprofile-use -fprofile-generate -O2",
|
||||
},
|
||||
]),
|
||||
);
|
||||
const check = report.checks.find((item) => item.id === "go.build_paths");
|
||||
expect(check?.status).toBe("not_observed");
|
||||
});
|
||||
});
|
||||
|
||||
describe("ReleaseExposureService Go linker -r search list", () => {
|
||||
it.each([["-r=$ORIGIN/../lib -s -w"], ["-r ${ORIGIN}/lib:$ORIGIN"]])(
|
||||
"does not read the ELF loader-expanded entries in %s as build paths",
|
||||
|
||||
@@ -38,11 +38,13 @@ const GO_FLAG_PATH =
|
||||
* Go's own tools reuse those letters: `-ldflags` takes `-B gobuildid` and
|
||||
* `-T 0x1000`, so their relative arguments are not paths. The exact field
|
||||
* `-I-` is GCC's include barrier, the same as `--include-barrier`, and names
|
||||
* no directory.
|
||||
* no directory. GCC profile directory options name a path in their explicit
|
||||
* equals form. The bare profile-use and profile-generate switches take no
|
||||
* following operand.
|
||||
*/
|
||||
const GO_COMPILER_SETTING = /^(?:CGO_[A-Z]+FLAGS|-gccgoflags)$/u;
|
||||
const GO_COMPILER_PATH_FLAG =
|
||||
/^(?:-(?:idirafter|imacros|include|iprefix|iquote|isysroot|isystem|[BFLT]|I(?!-$))=?\s*|--sysroot(?:=|\s+|$))(.*)$/su;
|
||||
/^(?:-(?:idirafter|imacros|include|iprefix|iquote|isysroot|isystem|[BFLT]|I(?!-$))=?\s*|--sysroot(?:=|\s+|$)|-fprofile-(?:dir|generate|use)=)(.*)$/su;
|
||||
/**
|
||||
* Linker options a C compiler forwards through `-Wl,a,b` or `-Xlinker a`. The
|
||||
* linker reads its own letters: `-L`, `-T` and `-I` (the ELF interpreter) take
|
||||
|
||||
Reference in new issue
Block a user