| 11640 | } |
| 11641 | |
| 11642 | static int extract_and_install_binary(extract_install_args_t args) { |
| 11643 | const char *tmp_archive = args.tmp_archive; |
| 11644 | const char *ext = args.ext; |
| 11645 | const char *bin_dest = args.bin_dest; |
| 11646 | FILE *f = fopen(tmp_archive, "rb"); |
| 11647 | if (!f) { |
| 11648 | (void)fprintf(stderr, "error: cannot open %s\n", tmp_archive); |
| 11649 | return CLI_TRUE; |
| 11650 | } |
| 11651 | if (fseek(f, 0, SEEK_END) != 0) { |
| 11652 | (void)fclose(f); |
| 11653 | cbm_unlink(tmp_archive); |
| 11654 | return CLI_TRUE; |
| 11655 | } |
| 11656 | long fsize = ftell(f); |
| 11657 | if (fsize <= 0 || fsize > INT_MAX || fseek(f, 0, SEEK_SET) != 0) { |
| 11658 | (void)fclose(f); |
| 11659 | cbm_unlink(tmp_archive); |
| 11660 | return CLI_TRUE; |
| 11661 | } |
| 11662 | |
| 11663 | unsigned char *data = malloc((size_t)fsize); |
| 11664 | if (!data) { |
| 11665 | (void)fclose(f); |
| 11666 | cbm_unlink(tmp_archive); |
| 11667 | return CLI_TRUE; |
| 11668 | } |
| 11669 | size_t bytes_read = fread(data, CLI_ELEM_SIZE, (size_t)fsize, f); |
| 11670 | int close_status = fclose(f); |
| 11671 | if (bytes_read != (size_t)fsize || close_status != 0) { |
| 11672 | free(data); |
| 11673 | cbm_unlink(tmp_archive); |
| 11674 | return CLI_TRUE; |
| 11675 | } |
| 11676 | |
| 11677 | int bin_len = 0; |
| 11678 | unsigned char *bin_data = NULL; |
| 11679 | if (strcmp(ext, "tar.gz") == 0) { |
| 11680 | bin_data = cbm_extract_binary_from_targz(data, (int)fsize, &bin_len); |
| 11681 | } else { |
| 11682 | bin_data = cbm_extract_binary_from_zip(data, (int)fsize, &bin_len); |
| 11683 | } |
| 11684 | free(data); |
| 11685 | cbm_unlink(tmp_archive); |
| 11686 | |
| 11687 | if (!bin_data || bin_len <= 0) { |
| 11688 | (void)fprintf(stderr, "error: binary not found in archive\n"); |
| 11689 | free(bin_data); |
| 11690 | return CLI_TRUE; |
| 11691 | } |
| 11692 | |
| 11693 | cbm_activation_transaction_t *binary_transaction = NULL; |
| 11694 | cbm_activation_transaction_status_t stage_status; |
| 11695 | cli_binary_validator_t validator = {{0}}; |
| 11696 | #ifdef __APPLE__ |
| 11697 | /* codesign replaces the signed file on current macOS releases. Publish and |
| 11698 | * sign a disposable private copy first, then stage the resulting immutable |
| 11699 | * bytes into the final transaction. */ |
no test coverage detected