diff --git a/src/charon/plugins/sql/pool.c b/src/charon/plugins/sql/pool.c index ebcc9adc7..6c0c1f5a6 100644 --- a/src/charon/plugins/sql/pool.c +++ b/src/charon/plugins/sql/pool.c @@ -173,22 +173,6 @@ static void status(void) exit(0); } -/** - * increment a chunk, as it would reprensent a network order integer - */ -static void increment_chunk(chunk_t chunk) -{ - int i; - - for (i = chunk.len - 1; i >= 0; i--) - { - if (++chunk.ptr[i] != 0) - { - return; - } - } -} - /** * ipsec pool --add - add a new pool */ @@ -233,7 +217,7 @@ static void add(char *name, host_t *start, host_t *end, int timeout) { break; } - increment_chunk(cur_addr); + chunk_increment(cur_addr); } if (db->get_driver(db) == DB_SQLITE) { @@ -331,7 +315,7 @@ static void resize(char *name, host_t *end) } while (count-- > 0) { - increment_chunk(cur_addr); + chunk_increment(cur_addr); db->execute(db, NULL, "INSERT INTO addresses (pool, address, identity, acquired, released) " "VALUES (?, ?, ?, ?, ?)", diff --git a/src/libstrongswan/chunk.c b/src/libstrongswan/chunk.c index bdea31188..acf3db1f4 100644 --- a/src/libstrongswan/chunk.c +++ b/src/libstrongswan/chunk.c @@ -449,6 +449,24 @@ int chunk_compare(chunk_t a, chunk_t b) return memcmp(a.ptr, b.ptr, len); }; + +/** + * Described in header. + */ +bool chunk_increment(chunk_t chunk) +{ + int i; + + for (i = chunk.len - 1; i >= 0; i--) + { + if (++chunk.ptr[i] != 0) + { + return FALSE; + } + } + return TRUE; +} + /** * Remove non-printable characters from a chunk. */ diff --git a/src/libstrongswan/chunk.h b/src/libstrongswan/chunk.h index 91b4442ef..3329a4a27 100644 --- a/src/libstrongswan/chunk.h +++ b/src/libstrongswan/chunk.h @@ -238,6 +238,14 @@ static inline bool chunk_equals(chunk_t a, chunk_t b) a.len == b.len && memeq(a.ptr, b.ptr, a.len); } +/** + * Increment a chunk, as it would reprensent a network order integer. + * + * @param chunk chunk to increment + * @return TRUE if an overflow occured + */ +bool chunk_increment(chunk_t chunk); + /** * Check if a chunk has printable characters only. *