summaryrefslogtreecommitdiffstats
path: root/src/server/image.c
diff options
context:
space:
mode:
authorSimon Rettberg2017-04-27 22:20:43 +0200
committerSimon Rettberg2017-04-27 22:20:43 +0200
commit696e24a2ca5e3d0812061e0ec8312214e07a3ea4 (patch)
tree15aa25b3b7c36fe3b8a8c4b4e34e53e75f7c4f38 /src/server/image.c
parent[SERVER] Remove stray line (diff)
downloaddnbd3-696e24a2ca5e3d0812061e0ec8312214e07a3ea4.tar.gz
dnbd3-696e24a2ca5e3d0812061e0ec8312214e07a3ea4.tar.xz
dnbd3-696e24a2ca5e3d0812061e0ec8312214e07a3ea4.zip
[SERVER] Make crclist handling endian-safe
Diffstat (limited to 'src/server/image.c')
-rw-r--r--src/server/image.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/server/image.c b/src/server/image.c
index 39d8f53..fedb971 100644
--- a/src/server/image.c
+++ b/src/server/image.c
@@ -907,6 +907,7 @@ static uint32_t* image_loadCrcList(const char * const imagePath, const int64_t f
} else {
uint32_t lists_crc = crc32( 0L, Z_NULL, 0 );
lists_crc = crc32( lists_crc, (Bytef*)retval, hashBlocks * sizeof(uint32_t) );
+ lists_crc = net_order_32( lists_crc );
if ( lists_crc != *masterCrc ) {
free( retval );
retval = NULL;
@@ -1259,11 +1260,12 @@ static bool image_clone(int sock, char *name, uint16_t revision, uint64_t imageS
if ( crc32len != 0 ) {
uint32_t lists_crc = crc32( 0L, Z_NULL, 0 );
lists_crc = crc32( lists_crc, (Bytef*)crc32list, crc32len );
+ lists_crc = net_order_32( lists_crc );
if ( lists_crc != masterCrc ) {
logadd( LOG_WARNING, "OTF-Clone: Corrupted CRC-32 list. ignored. (%s)", name );
} else {
int fd = open( crcFile, O_WRONLY | O_CREAT, 0644 );
- write( fd, &lists_crc, sizeof(uint32_t) );
+ write( fd, &masterCrc, sizeof(uint32_t) );
write( fd, crc32list, crc32len );
close( fd );
}
@@ -1353,6 +1355,7 @@ bool image_generateCrcFile(char *image)
crc = crc32( crc, (Bytef*)buffer, numBlocks * sizeof(crc) );
blocksToGo -= numBlocks;
}
+ crc = net_order_32( crc );
if ( pwrite( fdCrc, &crc, sizeof(crc), 0 ) != sizeof(crc) ) {
logadd( LOG_ERROR, "Could not write master crc to file" );
goto cleanup_fail;
@@ -1465,6 +1468,9 @@ bool image_checkBlocksCrc32(const int fd, uint32_t *crc32list, const int *blocks
return true;
}
+/**
+ * Calc CRC-32 of block. Value is returned as little endian.
+ */
static bool image_calcBlockCrc32(const int fd, const int block, const uint64_t realFilesize, uint32_t *crc)
{
char buffer[40000];
@@ -1498,6 +1504,7 @@ static bool image_calcBlockCrc32(const int fd, const int block, const uint64_t r
bytes -= len;
}
}
+ *crc = net_order_32( *crc );
return true;
}