Verify that the RDB version of the dump payload matches the one of this Redis * instance and that the checksum is ok. * If the DUMP payload looks valid C_OK is returned, otherwise C_ERR * is returned. */
| 5070 | * If the DUMP payload looks valid C_OK is returned, otherwise C_ERR |
| 5071 | * is returned. */ |
| 5072 | int verifyDumpPayload(unsigned char *p, size_t len) { |
| 5073 | unsigned char *footer; |
| 5074 | uint16_t rdbver; |
| 5075 | uint64_t crc; |
| 5076 | |
| 5077 | /* At least 2 bytes of RDB version and 8 of CRC64 should be present. */ |
| 5078 | if (len < 10) return C_ERR; |
| 5079 | footer = p+(len-10); |
| 5080 | |
| 5081 | /* Verify RDB version */ |
| 5082 | rdbver = (footer[1] << 8) | footer[0]; |
| 5083 | if (rdbver > RDB_VERSION) return C_ERR; |
| 5084 | |
| 5085 | if (server.skip_checksum_validation) |
| 5086 | return C_OK; |
| 5087 | |
| 5088 | /* Verify CRC64 */ |
| 5089 | crc = crc64(0,p,len-8); |
| 5090 | memrev64ifbe(&crc); |
| 5091 | return (memcmp(&crc,footer+2,8) == 0) ? C_OK : C_ERR; |
| 5092 | } |
| 5093 | |
| 5094 | /* DUMP keyname |
| 5095 | * DUMP is actually not used by Redis Cluster but it is the obvious |
no test coverage detected