Try to extract the target binary from a tar entry. Returns malloc'd data or NULL. */
| 6102 | |
| 6103 | /* Try to extract the target binary from a tar entry. Returns malloc'd data or NULL. */ |
| 6104 | static unsigned char *tar_try_extract_binary(const unsigned char *hdr, char typeflag, |
| 6105 | const char *name, const unsigned char *archive, |
| 6106 | size_t data_pos, long file_size, size_t total, |
| 6107 | int *out_len) { |
| 6108 | (void)hdr; |
| 6109 | if (typeflag != '0' && typeflag != '\0') { |
| 6110 | return NULL; |
| 6111 | } |
| 6112 | const char *basename = strrchr(name, '/'); |
| 6113 | basename = basename ? basename + CLI_SKIP_ONE : name; |
| 6114 | if (strncmp(basename, TAR_BINARY_NAME, TAR_BINARY_NAME_LEN) != 0) { |
| 6115 | return NULL; |
| 6116 | } |
| 6117 | if (data_pos + (size_t)file_size > total) { |
| 6118 | return NULL; |
| 6119 | } |
| 6120 | unsigned char *result = malloc((size_t)file_size); |
| 6121 | if (!result) { |
| 6122 | return NULL; |
| 6123 | } |
| 6124 | memcpy(result, archive + data_pos, (size_t)file_size); |
| 6125 | *out_len = (int)file_size; |
| 6126 | return result; |
| 6127 | } |
| 6128 | |
| 6129 | unsigned char *cbm_extract_binary_from_targz(const unsigned char *data, int data_len, |
| 6130 | int *out_len) { |
no outgoing calls
no test coverage detected