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
| 12001 | /* Hash `content` (len bytes) via a temp file and compare to expected hex. |
| 12002 | * Returns 1 on match, 0 otherwise. */ |
| 12003 | static int sha256_vector_ok(const void *content, size_t len, const char *expected) { |
| 12004 | char path[512]; |
| 12005 | snprintf(path, sizeof(path), "%s/cbm_sha_XXXXXX", cbm_tmpdir()); |
| 12006 | int fd = cbm_mkstemp(path); |
| 12007 | if (fd < 0) { |
| 12008 | return 0; |
| 12009 | } |
| 12010 | FILE *fp = fdopen(fd, "wb"); |
| 12011 | if (!fp) { |
| 12012 | return 0; |
| 12013 | } |
| 12014 | if (len > 0) { |
| 12015 | fwrite(content, 1, len, fp); |
| 12016 | } |
| 12017 | fclose(fp); |
| 12018 | |
| 12019 | char digest[128] = {0}; |
| 12020 | int rc = cbm_cli_sha256_file(path, digest, sizeof(digest)); |
| 12021 | remove(path); |
| 12022 | return rc == 0 && strcmp(digest, expected) == 0; |
| 12023 | } |
| 12024 | |
| 12025 | static bool cli_checksum_manifest_path(char *path, size_t path_size) { |
| 12026 | int written = snprintf(path, path_size, "%s/cbm-checksum-XXXXXX", cbm_tmpdir()); |
no test coverage detected