Try to extract the target binary from a tar entry. Returns malloc'd data or NULL. */
| 7116 | |
| 7117 | /* Try to extract the target binary from a tar entry. Returns malloc'd data or NULL. */ |
| 7118 | static unsigned char *tar_try_extract_binary(const unsigned char *hdr, char typeflag, |
| 7119 | const char *name, const unsigned char *archive, |
| 7120 | size_t data_pos, long file_size, size_t total, |
| 7121 | int *out_len) { |
| 7122 | (void)hdr; |
| 7123 | if (typeflag != '0' && typeflag != '\0') { |
| 7124 | return NULL; |
| 7125 | } |
| 7126 | const char *basename = strrchr(name, '/'); |
| 7127 | basename = basename ? basename + CLI_SKIP_ONE : name; |
| 7128 | if (strncmp(basename, TAR_BINARY_NAME, TAR_BINARY_NAME_LEN) != 0) { |
| 7129 | return NULL; |
| 7130 | } |
| 7131 | if (data_pos + (size_t)file_size > total) { |
| 7132 | return NULL; |
| 7133 | } |
| 7134 | unsigned char *result = malloc((size_t)file_size); |
| 7135 | if (!result) { |
| 7136 | return NULL; |
| 7137 | } |
| 7138 | memcpy(result, archive + data_pos, (size_t)file_size); |
| 7139 | *out_len = (int)file_size; |
| 7140 | return result; |
| 7141 | } |
| 7142 | |
| 7143 | unsigned char *cbm_extract_binary_from_targz(const unsigned char *data, int data_len, |
| 7144 | int *out_len) { |
no outgoing calls
no test coverage detected