| 11095 | } |
| 11096 | |
| 11097 | static int extract_and_install_binary(extract_install_args_t args) { |
| 11098 | const char *tmp_archive = args.tmp_archive; |
| 11099 | const char *ext = args.ext; |
| 11100 | const char *bin_dest = args.bin_dest; |
| 11101 | FILE *f = fopen(tmp_archive, "rb"); |
| 11102 | if (!f) { |
| 11103 | (void)fprintf(stderr, "error: cannot open %s\n", tmp_archive); |
| 11104 | return CLI_TRUE; |
| 11105 | } |
| 11106 | if (fseek(f, 0, SEEK_END) != 0) { |
| 11107 | (void)fclose(f); |
| 11108 | cbm_unlink(tmp_archive); |
| 11109 | return CLI_TRUE; |
| 11110 | } |
| 11111 | long fsize = ftell(f); |
| 11112 | if (fsize <= 0 || fsize > INT_MAX || fseek(f, 0, SEEK_SET) != 0) { |
| 11113 | (void)fclose(f); |
| 11114 | cbm_unlink(tmp_archive); |
| 11115 | return CLI_TRUE; |
| 11116 | } |
| 11117 | |
| 11118 | unsigned char *data = malloc((size_t)fsize); |
| 11119 | if (!data) { |
| 11120 | (void)fclose(f); |
| 11121 | cbm_unlink(tmp_archive); |
| 11122 | return CLI_TRUE; |
| 11123 | } |
| 11124 | size_t bytes_read = fread(data, CLI_ELEM_SIZE, (size_t)fsize, f); |
| 11125 | int close_status = fclose(f); |
| 11126 | if (bytes_read != (size_t)fsize || close_status != 0) { |
| 11127 | free(data); |
| 11128 | cbm_unlink(tmp_archive); |
| 11129 | return CLI_TRUE; |
| 11130 | } |
| 11131 | |
| 11132 | int bin_len = 0; |
| 11133 | unsigned char *bin_data = NULL; |
| 11134 | if (strcmp(ext, "tar.gz") == 0) { |
| 11135 | bin_data = cbm_extract_binary_from_targz(data, (int)fsize, &bin_len); |
| 11136 | } else { |
| 11137 | bin_data = cbm_extract_binary_from_zip(data, (int)fsize, &bin_len); |
| 11138 | } |
| 11139 | free(data); |
| 11140 | cbm_unlink(tmp_archive); |
| 11141 | |
| 11142 | if (!bin_data || bin_len <= 0) { |
| 11143 | (void)fprintf(stderr, "error: binary not found in archive\n"); |
| 11144 | free(bin_data); |
| 11145 | return CLI_TRUE; |
| 11146 | } |
| 11147 | |
| 11148 | cbm_activation_transaction_t *binary_transaction = NULL; |
| 11149 | cbm_activation_transaction_status_t stage_status; |
| 11150 | cli_binary_validator_t validator = {{0}}; |
| 11151 | #ifdef __APPLE__ |
| 11152 | /* codesign replaces the signed file on current macOS releases. Publish and |
| 11153 | * sign a disposable private copy first, then stage the resulting immutable |
| 11154 | * bytes into the final transaction. */ |
no test coverage detected