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

Function sha256_vector_ok

tests/test_cli.c:11930–11950  ·  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

11928/* Hash `content` (len bytes) via a temp file and compare to expected hex.
11929 * Returns 1 on match, 0 otherwise. */
11930static int sha256_vector_ok(const void *content, size_t len, const char *expected) {
11931 char path[512];
11932 snprintf(path, sizeof(path), "%s/cbm_sha_XXXXXX", cbm_tmpdir());
11933 int fd = cbm_mkstemp(path);
11934 if (fd < 0) {
11935 return 0;
11936 }
11937 FILE *fp = fdopen(fd, "wb");
11938 if (!fp) {
11939 return 0;
11940 }
11941 if (len > 0) {
11942 fwrite(content, 1, len, fp);
11943 }
11944 fclose(fp);
11945
11946 char digest[128] = {0};
11947 int rc = cbm_cli_sha256_file(path, digest, sizeof(digest));
11948 remove(path);
11949 return rc == 0 && strcmp(digest, expected) == 0;
11950}
11951
11952static bool cli_checksum_manifest_path(char *path, size_t path_size) {
11953 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