| 11145 | } |
| 11146 | |
| 11147 | static int extract_and_install_binary(extract_install_args_t args) { |
| 11148 | const char *tmp_archive = args.tmp_archive; |
| 11149 | const char *ext = args.ext; |
| 11150 | const char *bin_dest = args.bin_dest; |
| 11151 | FILE *f = fopen(tmp_archive, "rb"); |
| 11152 | if (!f) { |
| 11153 | (void)fprintf(stderr, "error: cannot open %s\n", tmp_archive); |
| 11154 | return CLI_TRUE; |
| 11155 | } |
| 11156 | if (fseek(f, 0, SEEK_END) != 0) { |
| 11157 | (void)fclose(f); |
| 11158 | cbm_unlink(tmp_archive); |
| 11159 | return CLI_TRUE; |
| 11160 | } |
| 11161 | long fsize = ftell(f); |
| 11162 | if (fsize <= 0 || fsize > INT_MAX || fseek(f, 0, SEEK_SET) != 0) { |
| 11163 | (void)fclose(f); |
| 11164 | cbm_unlink(tmp_archive); |
| 11165 | return CLI_TRUE; |
| 11166 | } |
| 11167 | |
| 11168 | unsigned char *data = malloc((size_t)fsize); |
| 11169 | if (!data) { |
| 11170 | (void)fclose(f); |
| 11171 | cbm_unlink(tmp_archive); |
| 11172 | return CLI_TRUE; |
| 11173 | } |
| 11174 | size_t bytes_read = fread(data, CLI_ELEM_SIZE, (size_t)fsize, f); |
| 11175 | int close_status = fclose(f); |
| 11176 | if (bytes_read != (size_t)fsize || close_status != 0) { |
| 11177 | free(data); |
| 11178 | cbm_unlink(tmp_archive); |
| 11179 | return CLI_TRUE; |
| 11180 | } |
| 11181 | |
| 11182 | int bin_len = 0; |
| 11183 | unsigned char *bin_data = NULL; |
| 11184 | if (strcmp(ext, "tar.gz") == 0) { |
| 11185 | bin_data = cbm_extract_binary_from_targz(data, (int)fsize, &bin_len); |
| 11186 | } else { |
| 11187 | bin_data = cbm_extract_binary_from_zip(data, (int)fsize, &bin_len); |
| 11188 | } |
| 11189 | free(data); |
| 11190 | cbm_unlink(tmp_archive); |
| 11191 | |
| 11192 | if (!bin_data || bin_len <= 0) { |
| 11193 | (void)fprintf(stderr, "error: binary not found in archive\n"); |
| 11194 | free(bin_data); |
| 11195 | return CLI_TRUE; |
| 11196 | } |
| 11197 | |
| 11198 | cbm_activation_transaction_t *binary_transaction = NULL; |
| 11199 | cbm_activation_transaction_status_t stage_status; |
| 11200 | cli_binary_validator_t validator = {{0}}; |
| 11201 | #ifdef __APPLE__ |
| 11202 | /* codesign replaces the signed file on current macOS releases. Publish and |
| 11203 | * sign a disposable private copy first, then stage the resulting immutable |
| 11204 | * bytes into the final transaction. */ |
no test coverage detected