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