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. */
| 5160 | * If the DUMP payload looks valid C_OK is returned, otherwise C_ERR |
| 5161 | * is returned. */ |
| 5162 | int verifyDumpPayload(unsigned char *p, size_t len) { |
| 5163 | unsigned char *footer; |
| 5164 | uint16_t rdbver; |
| 5165 | uint64_t crc; |
| 5166 | |
| 5167 | /* At least 2 bytes of RDB version and 8 of CRC64 should be present. */ |
| 5168 | if (len < 10) return C_ERR; |
| 5169 | footer = p+(len-10); |
| 5170 | |
| 5171 | /* Verify RDB version */ |
| 5172 | rdbver = (footer[1] << 8) | footer[0]; |
| 5173 | if (rdbver > RDB_VERSION) return C_ERR; |
| 5174 | |
| 5175 | if (cserver.skip_checksum_validation) |
| 5176 | return C_OK; |
| 5177 | |
| 5178 | /* Verify CRC64 */ |
| 5179 | crc = crc64(0,p,len-8); |
| 5180 | memrev64ifbe(&crc); |
| 5181 | return (memcmp(&crc,footer+2,8) == 0) ? C_OK : C_ERR; |
| 5182 | } |
| 5183 | |
| 5184 | /* DUMP keyname |
| 5185 | * DUMP is actually not used by Redis Cluster but it is the obvious |
no test coverage detected