commit - 01538ce4935fe05e87ef376f1ef3650b11731ca7
commit + eac2c4cda61825a5f030a46aa42cbbbc34294a02
blob - 93f8ca43c79a6d484e743add62d5a09d12e40970
blob + f274d7e931e5a3e179d311f5a26d0d901a9a77d7
--- libexec/got-fetch-pack/got-fetch-pack.c
+++ libexec/got-fetch-pack/got-fetch-pack.c
return NULL;
}
-static int
+static const struct got_error *
check_pack_hash(int fd, size_t sz, uint8_t *hcomp)
{
SHA1_CTX ctx;
ssize_t n, r, nr;
if (sz < 28)
- return -1;
+ return got_error(GOT_ERR_BAD_PACKFILE);
n = 0;
SHA1Init(&ctx);
nr = sz - n - 20;
r = readn(fd, buf, nr);
if (r != nr)
- return -1;
+ return got_error(GOT_ERR_BAD_PACKFILE);
SHA1Update(&ctx, buf, nr);
n += r;
}
SHA1Final(hcomp, &ctx);
if (readn(fd, hexpect, sizeof(hexpect)) != sizeof(hexpect))
- errx(1, "truncated packfile");
+ return got_error(GOT_ERR_BAD_PACKFILE);
if (memcmp(hcomp, hexpect, SHA1_DIGEST_LENGTH) != 0) {
got_sha1_digest_to_str(hcomp, s1, sizeof(s1));
got_sha1_digest_to_str(hexpect, s2, sizeof(s2));
- printf("hash mismatch %s != %s\n", s1, s2);
- return -1;
+ return got_error(GOT_ERR_BAD_PACKFILE);
}
- return 0;
+ return NULL;
}
static int
err = got_error_from_errno("lseek");
goto done;
}
- if (check_pack_hash(packfd, packsz, packid->sha1) == -1)
- err = got_error(GOT_ERR_BAD_PACKFILE);
+ err = check_pack_hash(packfd, packsz, packid->sha1);
done:
TAILQ_FOREACH(pe, &symrefs, entry) {
free((void *)pe->path);