MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / sha256_vector_ok

Function sha256_vector_ok

tests/test_cli.c:12512–12532  ·  view source on GitHub ↗

The self-update path verifies a downloaded archive against a published * checksum. That check is only meaningful if the digest is actually computed — * a broken hash command (it once invoked `shasum -a CBM_SZ_256`, an invalid * algorithm, from a bad macro rename inside the shell string) makes every * digest fail, and the caller then falls through and installs unverified. * Guard the digest it

Source from the content-addressed store, hash-verified

12510/* Hash `content` (len bytes) via a temp file and compare to expected hex.
12511 * Returns 1 on match, 0 otherwise. */
12512static int sha256_vector_ok(const void *content, size_t len, const char *expected) {
12513 char path[512];
12514 snprintf(path, sizeof(path), "%s/cbm_sha_XXXXXX", cbm_tmpdir());
12515 int fd = cbm_mkstemp(path);
12516 if (fd < 0) {
12517 return 0;
12518 }
12519 FILE *fp = fdopen(fd, "wb");
12520 if (!fp) {
12521 return 0;
12522 }
12523 if (len > 0) {
12524 fwrite(content, 1, len, fp);
12525 }
12526 fclose(fp);
12527
12528 char digest[128] = {0};
12529 int rc = cbm_cli_sha256_file(path, digest, sizeof(digest));
12530 remove(path);
12531 return rc == 0 && strcmp(digest, expected) == 0;
12532}
12533
12534static bool cli_checksum_manifest_path(char *path, size_t path_size) {
12535 int written = snprintf(path, path_size, "%s/cbm-checksum-XXXXXX", cbm_tmpdir());

Callers 1

test_cli.cFile · 0.85

Calls 3

cbm_tmpdirFunction · 0.85
cbm_mkstempFunction · 0.85
cbm_cli_sha256_fileFunction · 0.85

Tested by

no test coverage detected