| 7956 | } |
| 7957 | |
| 7958 | static bool cli_checksum_line_digest(const unsigned char *line, size_t line_length, |
| 7959 | const char *archive_name, size_t archive_name_length, |
| 7960 | char digest[SHA256_BUF_SIZE]) { |
| 7961 | if (!line || line_length <= SHA256_HEX_LEN || |
| 7962 | (line[SHA256_HEX_LEN] != (unsigned char)' ' && |
| 7963 | line[SHA256_HEX_LEN] != (unsigned char)'\t')) { |
| 7964 | return false; |
| 7965 | } |
| 7966 | size_t filename_offset = SHA256_HEX_LEN; |
| 7967 | while (filename_offset < line_length && (line[filename_offset] == (unsigned char)' ' || |
| 7968 | line[filename_offset] == (unsigned char)'\t')) { |
| 7969 | filename_offset++; |
| 7970 | } |
| 7971 | if (filename_offset < line_length && line[filename_offset] == (unsigned char)'*') { |
| 7972 | filename_offset++; |
| 7973 | } |
| 7974 | if (line_length - filename_offset != archive_name_length || |
| 7975 | memcmp(line + filename_offset, archive_name, archive_name_length) != 0) { |
| 7976 | return false; |
| 7977 | } |
| 7978 | |
| 7979 | static const char lower_hex[] = "0123456789abcdef"; |
| 7980 | for (size_t i = 0; i < SHA256_HEX_LEN; i++) { |
| 7981 | int nibble = cli_checksum_hex_nibble(line[i]); |
| 7982 | if (nibble < 0) { |
| 7983 | return false; |
| 7984 | } |
| 7985 | digest[i] = lower_hex[nibble]; |
| 7986 | } |
| 7987 | digest[SHA256_HEX_LEN] = '\0'; |
| 7988 | return true; |
| 7989 | } |
| 7990 | |
| 7991 | /* Parse one downloaded checksum manifest without trusting line truncation or |
| 7992 | * substring matches. This non-header symbol is intentionally exercised by the |
no test coverage detected