Skip to content

Commit 02fe73a

Browse files
committed
Checksum is checked only if payload version is >= 2
1 parent 3bd7bd2 commit 02fe73a

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/cloudsync.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,12 @@
4949
#define CLOUDSYNC_INIT_NTABLES 64
5050
#define CLOUDSYNC_MIN_DB_VERSION 0
5151

52-
#define CLOUDSYNC_PAYLOAD_MINBUF_SIZE 512*1024
53-
#define CLOUDSYNC_PAYLOAD_VERSION 1
54-
#define CLOUDSYNC_PAYLOAD_SIGNATURE 'CLSY'
52+
#define CLOUDSYNC_PAYLOAD_MINBUF_SIZE 512*1024
53+
#define CLOUDSYNC_PAYLOAD_SIGNATURE 'CLSY'
54+
#define CLOUDSYNC_PAYLOAD_VERSION_ORIGNAL 1
55+
#define CLOUDSYNC_PAYLOAD_VERSION_1 CLOUDSYNC_PAYLOAD_VERSION_ORIGNAL
56+
#define CLOUDSYNC_PAYLOAD_VERSION_2 2
57+
#define CLOUDSYNC_PAYLOAD_MIN_VERSION_WITH_CHECKSUM CLOUDSYNC_PAYLOAD_VERSION_2
5558

5659
#ifndef MAX
5760
#define MAX(a, b) (((a)>(b))?(a):(b))
@@ -2010,7 +2013,7 @@ void cloudsync_payload_header_init (cloudsync_payload_header *header, uint32_t e
20102013
sscanf(CLOUDSYNC_VERSION, "%d.%d.%d", &major, &minor, &patch);
20112014

20122015
header->signature = htonl(CLOUDSYNC_PAYLOAD_SIGNATURE);
2013-
header->version = CLOUDSYNC_PAYLOAD_VERSION;
2016+
header->version = CLOUDSYNC_PAYLOAD_VERSION_2;
20142017
header->libversion[0] = (uint8_t)major;
20152018
header->libversion[1] = (uint8_t)minor;
20162019
header->libversion[2] = (uint8_t)patch;
@@ -2187,7 +2190,7 @@ int cloudsync_payload_apply (cloudsync_context *data, const char *payload, int b
21872190
// decode header
21882191
cloudsync_payload_header header;
21892192
memcpy(&header, payload, sizeof(cloudsync_payload_header));
2190-
2193+
21912194
header.signature = ntohl(header.signature);
21922195
header.expanded_size = ntohl(header.expanded_size);
21932196
header.ncols = ntohs(header.ncols);
@@ -2210,10 +2213,12 @@ int cloudsync_payload_apply (cloudsync_context *data, const char *payload, int b
22102213
const char *buffer = payload + sizeof(cloudsync_payload_header);
22112214
blen -= sizeof(cloudsync_payload_header);
22122215

2213-
// sanity check checksum
2214-
uint64_t checksum = pk_checksum(buffer, blen);
2215-
if (cloudsync_payload_checksum_verify(&header, checksum) == false) {
2216-
return cloudsync_set_error(data, "Error on cloudsync_payload_apply: invalid checksum", DBRES_MISUSE);
2216+
// sanity check checksum (only if version is >= 2)
2217+
if (header.version >= CLOUDSYNC_PAYLOAD_MIN_VERSION_WITH_CHECKSUM) {
2218+
uint64_t checksum = pk_checksum(buffer, blen);
2219+
if (cloudsync_payload_checksum_verify(&header, checksum) == false) {
2220+
return cloudsync_set_error(data, "Error on cloudsync_payload_apply: invalid checksum", DBRES_MISUSE);
2221+
}
22172222
}
22182223

22192224
// check if payload is compressed

0 commit comments

Comments
 (0)