Try to extract the target binary from a tar entry. Returns malloc'd data or NULL. */
| 6328 | |
| 6329 | /* Try to extract the target binary from a tar entry. Returns malloc'd data or NULL. */ |
| 6330 | static unsigned char *tar_try_extract_binary(const unsigned char *hdr, char typeflag, |
| 6331 | const char *name, const unsigned char *archive, |
| 6332 | size_t data_pos, long file_size, size_t total, |
| 6333 | int *out_len) { |
| 6334 | (void)hdr; |
| 6335 | if (typeflag != '0' && typeflag != '\0') { |
| 6336 | return NULL; |
| 6337 | } |
| 6338 | const char *basename = strrchr(name, '/'); |
| 6339 | basename = basename ? basename + CLI_SKIP_ONE : name; |
| 6340 | if (strncmp(basename, TAR_BINARY_NAME, TAR_BINARY_NAME_LEN) != 0) { |
| 6341 | return NULL; |
| 6342 | } |
| 6343 | if (data_pos + (size_t)file_size > total) { |
| 6344 | return NULL; |
| 6345 | } |
| 6346 | unsigned char *result = malloc((size_t)file_size); |
| 6347 | if (!result) { |
| 6348 | return NULL; |
| 6349 | } |
| 6350 | memcpy(result, archive + data_pos, (size_t)file_size); |
| 6351 | *out_len = (int)file_size; |
| 6352 | return result; |
| 6353 | } |
| 6354 | |
| 6355 | unsigned char *cbm_extract_binary_from_targz(const unsigned char *data, int data_len, |
| 6356 | int *out_len) { |
no outgoing calls
no test coverage detected