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