mirror of
https://github.com/Twigpine/node.git
synced 2026-11-08 07:38:18 -10:00
Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
923d47d491 | ||
|
|
f9942ee710 | ||
|
|
bfc44f926d | ||
|
|
65f5989a1d | ||
|
|
4725146db2 |
No files matched your search
@@ -3153,6 +3153,12 @@ struct RefUpdate {
|
||||
ref_name: String,
|
||||
}
|
||||
|
||||
/// A git object id is 40 hex chars; length alone is not enough, since a peer
|
||||
/// can send 40 arbitrary bytes (#398).
|
||||
fn is_hex_sha(s: &str) -> bool {
|
||||
s.len() == 40 && s.bytes().all(|b| b.is_ascii_hexdigit())
|
||||
}
|
||||
|
||||
/// Parse git receive-pack pkt-line ref updates from the request body.
|
||||
/// Format per line: `<40-hex-old> <40-hex-new> <refname>[NUL capabilities]\n`
|
||||
fn parse_ref_updates(body: &[u8]) -> Vec<RefUpdate> {
|
||||
@@ -3194,7 +3200,7 @@ fn parse_ref_updates(body: &[u8]) -> Vec<RefUpdate> {
|
||||
.trim_end_matches('\n');
|
||||
|
||||
let parts: Vec<&str> = line.splitn(3, ' ').collect();
|
||||
if parts.len() == 3 && parts[0].len() == 40 && parts[1].len() == 40 {
|
||||
if parts.len() == 3 && is_hex_sha(parts[0]) && is_hex_sha(parts[1]) {
|
||||
updates.push(RefUpdate {
|
||||
old_sha: parts[0].to_string(),
|
||||
new_sha: parts[1].to_string(),
|
||||
@@ -3488,6 +3494,45 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
// #398: a peer-supplied pkt-line whose 40-byte "SHA" fields carry non-hex
|
||||
// content must be dropped, not forwarded into RefUpdate events, branch_cid
|
||||
// rows, and sync-notify JSON as a canonical-looking identifier.
|
||||
#[test]
|
||||
fn parse_ref_updates_requires_hex_shas() {
|
||||
let sha_a = "a".repeat(40);
|
||||
let sha_b = "b".repeat(40);
|
||||
let pkt = |old: &str, new: &str, refname: &str| {
|
||||
let line = format!("{old} {new} {refname}");
|
||||
format!("{:04x}{}0000", line.len() + 4, line).into_bytes()
|
||||
};
|
||||
|
||||
// Valid 40-hex old + new -> accepted.
|
||||
let updates = parse_ref_updates(&pkt(&sha_a, &sha_b, "refs/heads/main"));
|
||||
assert_eq!(updates.len(), 1);
|
||||
assert_eq!(updates[0].old_sha, sha_a);
|
||||
assert_eq!(updates[0].new_sha, sha_b);
|
||||
assert_eq!(updates[0].ref_name, "refs/heads/main");
|
||||
|
||||
// 40-byte non-hex fields -> dropped.
|
||||
let junk = "Z".repeat(40);
|
||||
assert!(parse_ref_updates(&pkt(&junk, &sha_b, "refs/heads/main")).is_empty());
|
||||
assert!(parse_ref_updates(&pkt(&sha_a, &junk, "refs/heads/main")).is_empty());
|
||||
|
||||
// Wrong lengths -> dropped.
|
||||
assert!(parse_ref_updates(&pkt(&"a".repeat(39), &sha_b, "refs/heads/main")).is_empty());
|
||||
assert!(parse_ref_updates(&pkt(&sha_a, &"b".repeat(41), "refs/heads/main")).is_empty());
|
||||
|
||||
// A bad line among good ones drops only the bad line.
|
||||
let sha_c = "c".repeat(40);
|
||||
let bad = pkt(&junk, &sha_b, "refs/heads/bad");
|
||||
let good = pkt(&sha_a, &sha_c, "refs/heads/good");
|
||||
let mut mixed = bad[..bad.len() - 4].to_vec(); // strip trailing flush
|
||||
mixed.extend_from_slice(&good);
|
||||
let updates = parse_ref_updates(&mixed);
|
||||
assert_eq!(updates.len(), 1);
|
||||
assert_eq!(updates[0].ref_name, "refs/heads/good");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn git_service_app_error_classifies_timeout_bad_request_and_git() {
|
||||
// GitServiceTimeout carried through anyhow -> 504 Timeout.
|
||||
@@ -6260,6 +6305,9 @@ mod tests {
|
||||
// Long enough that the git-service timeout is never what ends this push; the
|
||||
// disconnect is.
|
||||
cfg.git_service_timeout_secs = 600;
|
||||
// Lock-path test, not owner-push authorization: pin off so the default-on gate
|
||||
// does not reject the proof DID before receive-pack runs.
|
||||
cfg.enforce_owner_push = false;
|
||||
state.config = std::sync::Arc::new(cfg);
|
||||
state
|
||||
.db
|
||||
@@ -6430,6 +6478,9 @@ mod tests {
|
||||
None,
|
||||
crate::git::repo_store::build_lock_pool(&pool, 4, std::time::Duration::from_secs(5)),
|
||||
);
|
||||
let mut cfg = (*state.config).clone();
|
||||
cfg.enforce_owner_push = false;
|
||||
state.config = std::sync::Arc::new(cfg);
|
||||
state
|
||||
.db
|
||||
.upsert_mirror_repo(owner, name, "/tmp/z6succ-sc1", None, false)
|
||||
@@ -6516,6 +6567,9 @@ mod tests {
|
||||
let owner = "z6lockpool";
|
||||
let name = "lp1";
|
||||
let mut state = crate::test_support::test_state(pool.clone()).await;
|
||||
let mut cfg = (*state.config).clone();
|
||||
cfg.enforce_owner_push = false;
|
||||
state.config = std::sync::Arc::new(cfg);
|
||||
// One lock-pool connection, short checkout timeout so the exhaustion surfaces
|
||||
// promptly rather than at the handler's own acquire deadline.
|
||||
state.repo_store = crate::git::repo_store::RepoStore::new(
|
||||
|
||||
@@ -60,7 +60,7 @@ pub(crate) async fn run_to_writer(args: WhoamiArgs, w: &mut impl std::io::Write)
|
||||
}
|
||||
Ok(resp) => {
|
||||
let status = resp.status();
|
||||
let raw = read_body_capped(resp, 8 * 1024).await;
|
||||
let raw = read_body_capped(resp, 8 * 1024).await.text;
|
||||
let msg = serde_json::from_str::<Value>(&raw)
|
||||
.ok()
|
||||
.and_then(|v| {
|
||||
|
||||
Reference in new issue
Block a user