diff options
author | Jan Hutter <jhutter@hsr.ch> | 2005-11-16 15:29:31 +0000 |
---|---|---|
committer | Jan Hutter <jhutter@hsr.ch> | 2005-11-16 15:29:31 +0000 |
commit | de257bc0be2af3b190e455ec9f1c363ac84d96d4 (patch) | |
tree | b3c725b24b617ada1f0244423b158eb43f8651d7 /Source | |
parent | d5fc0f731d2eb6dcc11e680b2e77890b7ba01725 (diff) | |
download | strongswan-de257bc0be2af3b190e455ec9f1c363ac84d96d4.tar.bz2 strongswan-de257bc0be2af3b190e455ec9f1c363ac84d96d4.tar.xz |
- fixed bug of generator
Diffstat (limited to 'Source')
-rw-r--r-- | Source/charon/generator.c | 17 | ||||
-rw-r--r-- | Source/charon/generator.h | 4 | ||||
-rw-r--r-- | Source/charon/testcases/generator_test.c | 5 | ||||
-rw-r--r-- | Source/charon/testcases/testcases.c | 2 | ||||
-rw-r--r-- | Source/charon/utils/allocator.c | 10 |
5 files changed, 28 insertions, 10 deletions
diff --git a/Source/charon/generator.c b/Source/charon/generator.c index dfbac5f6e..bca13b123 100644 --- a/Source/charon/generator.c +++ b/Source/charon/generator.c @@ -269,10 +269,6 @@ static size_t get_current_buffer_space (private_generator_t *this) { /* we know, one byte more */ size_t space = (this->roof_position) - (this->out_position); - if (this->current_bit == 0) - { - space++; - } return (space); } @@ -465,6 +461,13 @@ static status_t generate_reserved_field (private_generator_t *this,int bits) /* one bit processing */ u_int8_t reserved_bit = ~(1 << (7 - this->current_bit)); *(this->out_position) = *(this->out_position) & reserved_bit; + if (this->current_bit == 0) + { + /* memory must be zero */ + *(this->out_position) = 0x00; + } + + this->current_bit++; if (this->current_bit >= 8) { @@ -512,6 +515,11 @@ static status_t generate_flag (private_generator_t *this,u_int32_t offset) { return status; } + if (this->current_bit == 0) + { + /* memory must be zero */ + *(this->out_position) = 0x00; + } *(this->out_position) = *(this->out_position) | flag; @@ -563,6 +571,7 @@ static status_t make_space_available (private_generator_t *this, size_t bits) new_buffer = allocator_realloc(this->buffer,new_buffer_size); if (new_buffer == NULL) { + this->logger->log(this->logger,CONTROL_MORE,"Fatal error: Reallocation of buffer failed!!!"); return OUT_OF_RES; } diff --git a/Source/charon/generator.h b/Source/charon/generator.h index a23a9573a..436899bc4 100644 --- a/Source/charon/generator.h +++ b/Source/charon/generator.h @@ -31,12 +31,12 @@ * Generating is done in a data buffer. * This is thehe start size of this buffer in Bytes. */ -#define GENERATOR_DATA_BUFFER_SIZE 3000 +#define GENERATOR_DATA_BUFFER_SIZE 10 /** * Number of bytes to increase the buffer, if it is to small. */ -#define GENERATOR_DATA_BUFFER_INCREASE_VALUE 1000 +#define GENERATOR_DATA_BUFFER_INCREASE_VALUE 5 /** *A generator_t object which generates payloads of specific type. diff --git a/Source/charon/testcases/generator_test.c b/Source/charon/testcases/generator_test.c index 3b36bf37b..7a18879eb 100644 --- a/Source/charon/testcases/generator_test.c +++ b/Source/charon/testcases/generator_test.c @@ -431,6 +431,8 @@ void test_generator_with_proposal_substructure(tester_t *tester) 0x00,0x00,0x00,0x04, 0x69,0x6A,0x6B,0x6C }; + logger->log_bytes(logger,RAW,"expected transform",expected_generation,sizeof(expected_generation)); + tester->assert_true(tester,(memcmp(expected_generation,generated_data.ptr,sizeof(expected_generation)) == 0), "compare generated data"); allocator_free_chunk(generated_data); @@ -607,6 +609,9 @@ void test_generator_with_sa_payload(tester_t *tester) 0x07,0x05,0x00,0x00, }; + + logger->log_bytes(logger,RAW,"expected transform",expected_generation,sizeof(expected_generation)); + tester->assert_true(tester,(memcmp(expected_generation,generated_data.ptr,sizeof(expected_generation)) == 0), "compare generated data"); allocator_free_chunk(generated_data); diff --git a/Source/charon/testcases/testcases.c b/Source/charon/testcases/testcases.c index 36025fcb8..22ac640e3 100644 --- a/Source/charon/testcases/testcases.c +++ b/Source/charon/testcases/testcases.c @@ -200,7 +200,7 @@ logger_manager_t *global_logger_manager; &linked_list_insert_and_remove_test, &thread_pool_test, &job_queue_test1, -/* &event_queue_test, ERRROR */ + &event_queue_test, &send_queue_test, &scheduler_test, &socket_test, diff --git a/Source/charon/utils/allocator.c b/Source/charon/utils/allocator.c index 4c65bbbf0..dcb4e4231 100644 --- a/Source/charon/utils/allocator.c +++ b/Source/charon/utils/allocator.c @@ -328,15 +328,19 @@ chunk_t allocator_alloc_as_chunk(size_t bytes) void * allocator_realloc(void * old, size_t newsize) { - return realloc(old,newsize); + void *data = realloc(old,newsize); + return data; } void * allocator_clone_bytes(void * pointer, size_t size) { + void *data; data = malloc(size); - if (data == NULL){ return NULL;} - memcpy(data,pointer,size); + + if (data == NULL){return NULL;} + memmove(data,pointer,size); + return (data); } |