Fix several integer overflow bugs
parent
71dfff86a7
commit
7840ba3183
|
@ -41,7 +41,7 @@ int bs_analyze_thread(bs_engine_t *engine){
|
|||
atp.engine = engine;
|
||||
pthread_spin_init(&atp.spinlock, PTHREAD_PROCESS_PRIVATE );
|
||||
atp.next_offset = 0;
|
||||
atp.blocks = (engine->file.size + engine->parameters.blocksize - 1) / engine->parameters.blocksize;
|
||||
atp.blocks = (int)(((long)engine->file.size + (long)engine->parameters.blocksize - 1) / engine->parameters.blocksize);
|
||||
|
||||
int s = merkle_create(&engine->merkle.local, 2, atp.blocks);
|
||||
if (s<0)
|
||||
|
@ -97,12 +97,12 @@ int bs_analyzer_thread(struct analyzer_thread_parm *atp){
|
|||
if (offset >= atp->engine->file.size)
|
||||
break;
|
||||
|
||||
int size = atp->engine->file.size - offset;
|
||||
long size = atp->engine->file.size - offset;
|
||||
if (size > atp->engine->parameters.blocksize)
|
||||
size = atp->engine->parameters.blocksize;
|
||||
|
||||
uint64_t hash = dhash(&atp->engine->file.mmap[offset], size);
|
||||
merkle_set(atp->engine->merkle.local, atp->engine->merkle.local->parameters.depth, offset / atp->engine->parameters.blocksize, hash);
|
||||
merkle_set(atp->engine->merkle.local, atp->engine->merkle.local->parameters.depth, (int)(offset / atp->engine->parameters.blocksize), hash);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -37,7 +37,7 @@ int bs_transfer_thread(bs_engine_t *engine){
|
|||
|
||||
}
|
||||
|
||||
fprintf(stdout, "transfering blocks %d of %d blocks need to be transfered (%d%%).\n", changed_blocks, count_blocks, 100 * changed_blocks / count_blocks);
|
||||
fprintf(stdout, "transfering blocks: %d of %d blocks need to be transfered (%d%%).\n", changed_blocks, count_blocks, (int)((100l * changed_blocks) / count_blocks));
|
||||
fflush(stdout);
|
||||
|
||||
if (engine->tool_flags & BS_DEBUG){
|
||||
|
@ -62,7 +62,7 @@ int bs_transfer_thread(bs_engine_t *engine){
|
|||
if (bs_msg_queue_pop(&engine->queues.pool, &msg, Q_WAIT))
|
||||
fatal("could not pop message from pool\n", 0);
|
||||
|
||||
long offset = n * engine->parameters.blocksize;
|
||||
long offset = ((long)n) * engine->parameters.blocksize;
|
||||
int size = engine->parameters.blocksize;
|
||||
|
||||
if ((offset + size) > engine->file.size)
|
||||
|
@ -95,7 +95,7 @@ int bs_transfer_thread(bs_engine_t *engine){
|
|||
fatal("could not receive transfer messge\n", 0);
|
||||
|
||||
if (msg->msg_type == (BS_MSG_BLOCKDATA | BS_MSG_RESPONSE)){
|
||||
long offset = msg->transfer.blockno * engine->parameters.blocksize;
|
||||
long offset = ((long)msg->transfer.blockno) * engine->parameters.blocksize;
|
||||
memcpy(&engine->file.mmap[offset], msg->payload, msg->payload_length);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue