pub(super) struct Rule {
pub(super) id: &'static str,
pub(super) reason: &'static str,
pub(super) matches: fn(&str, &str) -> bool,
}
pub(super) const RULES: &[Rule] = &[
Rule {
id: "own-executable",
reason: "asks the operating system for the running executable, the first step of starting the wrapper again",
matches: |line, _joined| {
return line.contains("current_exe") || line.contains("/proc/self/exe");
},
},
Rule {
id: "argv0-dispatch",
reason: "reads the program name the wrapper was started as, which only matters for a wrapper that is started under another name",
matches: |line, _joined| {
return ["args_os().next()", "args().next()", ".nth(0)", "argv[0]", "arg0("]
.iter()
.any(|needle| {
return line.contains(needle);
});
},
},
Rule {
id: "shell-text",
reason: "writes or starts shell text; the wrapper writes no shell script, function or `sh -c`",
matches: |line, _joined| {
return ["/bin/sh", "/bin/bash", "#!/", "Command::new(\"sh\")", "Command::new(\"bash\")", "\"$@\"", "exec \\\"$"]
.iter()
.any(|needle| {
return line.contains(needle);
});
},
},
Rule {
id: "hook-command",
reason: "defines a Git hook or hook command; the wrapper injects no hook at all, the upload is a child the parent runs",
matches: |line, _joined| {
return line.contains(".command=") || line.contains(".event=pre-push");
},
},
Rule {
id: "management-word",
reason: "passes the management words to a process, which would start the wrapper's own management entry",
matches: |line, _joined| {
return line.contains(".arg(\"cli-git\"")
|| line.contains(".arg(MANAGEMENT_COMMAND")
|| line.contains("args([\"cli-git\"")
|| line.contains("HOOK_ENTRY");
},
},
Rule {
id: "spawn-own-executable",
reason: "starts a process from the wrapper's own executable path",
matches: |line, joined| {
return line.contains("Command::new(")
&& ["own_executable", "executable.as_path()", "inputs.own", "WRAPPER", "request.own"]
.iter()
.any(|needle| {
return joined.contains(needle);
});
},
},
];
pub(super) struct Allowed {
pub(super) file: &'static str,
pub(super) rule: &'static str,
pub(super) why: &'static str,
}
pub(super) const ALLOWED: &[Allowed] = &[
Allowed {
file: "real_git.rs",
rule: "own-executable",
why: "identification only: the path is excluded from the search for the real Git, and nothing is started from it",
},
Allowed {
file: "doctor.rs",
rule: "shell-text",
why: "the text git-lfs itself writes as its hook shim, held only to recognise that shim; the wrapper never writes it",
},
];