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
| 11836 | /* Hash `content` (len bytes) via a temp file and compare to expected hex. |
| 11837 | * Returns 1 on match, 0 otherwise. */ |
| 11838 | static int sha256_vector_ok(const void *content, size_t len, const char *expected) { |
| 11839 | char path[512]; |
| 11840 | snprintf(path, sizeof(path), "%s/cbm_sha_XXXXXX", cbm_tmpdir()); |
| 11841 | int fd = cbm_mkstemp(path); |
| 11842 | if (fd < 0) { |
| 11843 | return 0; |
| 11844 | } |
| 11845 | FILE *fp = fdopen(fd, "wb"); |
| 11846 | if (!fp) { |
| 11847 | return 0; |
| 11848 | } |
| 11849 | if (len > 0) { |
| 11850 | fwrite(content, 1, len, fp); |
| 11851 | } |
| 11852 | fclose(fp); |
| 11853 | |
| 11854 | char digest[128] = {0}; |
| 11855 | int rc = cbm_cli_sha256_file(path, digest, sizeof(digest)); |
| 11856 | remove(path); |
| 11857 | return rc == 0 && strcmp(digest, expected) == 0; |
| 11858 | } |
| 11859 | |
| 11860 | static bool cli_checksum_manifest_path(char *path, size_t path_size) { |
| 11861 | int written = snprintf(path, path_size, "%s/cbm-checksum-XXXXXX", cbm_tmpdir()); |
no test coverage detected