diff options
Diffstat (limited to 'src/libstrongswan/utils')
-rw-r--r-- | src/libstrongswan/utils/chunk.c | 62 | ||||
-rw-r--r-- | src/libstrongswan/utils/chunk.h | 18 | ||||
-rw-r--r-- | src/libstrongswan/utils/compat/android.h | 17 | ||||
-rw-r--r-- | src/libstrongswan/utils/cpu_feature.c | 2 | ||||
-rw-r--r-- | src/libstrongswan/utils/identification.c | 9 | ||||
-rw-r--r-- | src/libstrongswan/utils/identification.h | 2 | ||||
-rw-r--r-- | src/libstrongswan/utils/integrity_checker.c | 10 | ||||
-rw-r--r-- | src/libstrongswan/utils/integrity_checker.h | 8 | ||||
-rw-r--r-- | src/libstrongswan/utils/leak_detective.c | 34 | ||||
-rw-r--r-- | src/libstrongswan/utils/utils.c | 2 | ||||
-rw-r--r-- | src/libstrongswan/utils/utils/align.c | 6 | ||||
-rw-r--r-- | src/libstrongswan/utils/utils/align.h | 2 | ||||
-rw-r--r-- | src/libstrongswan/utils/utils/byteorder.h | 47 | ||||
-rw-r--r-- | src/libstrongswan/utils/utils/memory.c | 2 | ||||
-rw-r--r-- | src/libstrongswan/utils/utils/memory.h | 2 | ||||
-rw-r--r-- | src/libstrongswan/utils/utils/string.h | 8 | ||||
-rw-r--r-- | src/libstrongswan/utils/utils/time.c | 2 | ||||
-rw-r--r-- | src/libstrongswan/utils/utils/types.h | 15 |
18 files changed, 146 insertions, 102 deletions
diff --git a/src/libstrongswan/utils/chunk.c b/src/libstrongswan/utils/chunk.c index c4471be70..2f824a259 100644 --- a/src/libstrongswan/utils/chunk.c +++ b/src/libstrongswan/utils/chunk.c @@ -775,25 +775,25 @@ bool chunk_printable(chunk_t chunk, chunk_t *sane, char replace) /** * Helper functions for chunk_mac() */ -static inline u_int64_t sipget(u_char *in) +static inline uint64_t sipget(u_char *in) { - u_int64_t v = 0; + uint64_t v = 0; int i; for (i = 0; i < 64; i += 8, ++in) { - v |= ((u_int64_t)*in) << i; + v |= ((uint64_t)*in) << i; } return v; } -static inline u_int64_t siprotate(u_int64_t v, int shift) +static inline uint64_t siprotate(uint64_t v, int shift) { return (v << shift) | (v >> (64 - shift)); } -static inline void sipround(u_int64_t *v0, u_int64_t *v1, u_int64_t *v2, - u_int64_t *v3) +static inline void sipround(uint64_t *v0, uint64_t *v1, uint64_t *v2, + uint64_t *v3) { *v0 += *v1; *v1 = siprotate(*v1, 13); @@ -814,8 +814,8 @@ static inline void sipround(u_int64_t *v0, u_int64_t *v1, u_int64_t *v2, *v3 ^= *v0; } -static inline void sipcompress(u_int64_t *v0, u_int64_t *v1, u_int64_t *v2, - u_int64_t *v3, u_int64_t m) +static inline void sipcompress(uint64_t *v0, uint64_t *v1, uint64_t *v2, + uint64_t *v3, uint64_t m) { *v3 ^= m; sipround(v0, v1, v2, v3); @@ -823,28 +823,28 @@ static inline void sipcompress(u_int64_t *v0, u_int64_t *v1, u_int64_t *v2, *v0 ^= m; } -static inline u_int64_t siplast(size_t len, u_char *pos) +static inline uint64_t siplast(size_t len, u_char *pos) { - u_int64_t b; + uint64_t b; int rem = len & 7; - b = ((u_int64_t)len) << 56; + b = ((uint64_t)len) << 56; switch (rem) { case 7: - b |= ((u_int64_t)pos[6]) << 48; + b |= ((uint64_t)pos[6]) << 48; case 6: - b |= ((u_int64_t)pos[5]) << 40; + b |= ((uint64_t)pos[5]) << 40; case 5: - b |= ((u_int64_t)pos[4]) << 32; + b |= ((uint64_t)pos[4]) << 32; case 4: - b |= ((u_int64_t)pos[3]) << 24; + b |= ((uint64_t)pos[3]) << 24; case 3: - b |= ((u_int64_t)pos[2]) << 16; + b |= ((uint64_t)pos[2]) << 16; case 2: - b |= ((u_int64_t)pos[1]) << 8; + b |= ((uint64_t)pos[1]) << 8; case 1: - b |= ((u_int64_t)pos[0]); + b |= ((uint64_t)pos[0]); break; case 0: break; @@ -855,9 +855,9 @@ static inline u_int64_t siplast(size_t len, u_char *pos) /** * Caculate SipHash-2-4 with an optional first block given as argument. */ -static u_int64_t chunk_mac_inc(chunk_t chunk, u_char *key, u_int64_t m) +static uint64_t chunk_mac_inc(chunk_t chunk, u_char *key, uint64_t m) { - u_int64_t v0, v1, v2, v3, k0, k1; + uint64_t v0, v1, v2, v3, k0, k1; size_t len = chunk.len; u_char *pos = chunk.ptr, *end; @@ -896,7 +896,7 @@ static u_int64_t chunk_mac_inc(chunk_t chunk, u_char *key, u_int64_t m) /** * Described in header. */ -u_int64_t chunk_mac(chunk_t chunk, u_char *key) +uint64_t chunk_mac(chunk_t chunk, u_char *key) { return chunk_mac_inc(chunk, key, 0); } @@ -957,16 +957,16 @@ void chunk_hash_seed() /** * Described in header. */ -u_int32_t chunk_hash_inc(chunk_t chunk, u_int32_t hash) +uint32_t chunk_hash_inc(chunk_t chunk, uint32_t hash) { /* we could use a mac of the previous hash, but this is faster */ - return chunk_mac_inc(chunk, key, ((u_int64_t)hash) << 32 | hash); + return chunk_mac_inc(chunk, key, ((uint64_t)hash) << 32 | hash); } /** * Described in header. */ -u_int32_t chunk_hash(chunk_t chunk) +uint32_t chunk_hash(chunk_t chunk) { return chunk_mac(chunk, key); } @@ -974,15 +974,15 @@ u_int32_t chunk_hash(chunk_t chunk) /** * Described in header. */ -u_int32_t chunk_hash_static_inc(chunk_t chunk, u_int32_t hash) +uint32_t chunk_hash_static_inc(chunk_t chunk, uint32_t hash) { /* we could use a mac of the previous hash, but this is faster */ - return chunk_mac_inc(chunk, static_key, ((u_int64_t)hash) << 32 | hash); + return chunk_mac_inc(chunk, static_key, ((uint64_t)hash) << 32 | hash); } /** * Described in header. */ -u_int32_t chunk_hash_static(chunk_t chunk) +uint32_t chunk_hash_static(chunk_t chunk) { return chunk_mac(chunk, static_key); } @@ -990,9 +990,9 @@ u_int32_t chunk_hash_static(chunk_t chunk) /** * Described in header. */ -u_int16_t chunk_internet_checksum_inc(chunk_t data, u_int16_t checksum) +uint16_t chunk_internet_checksum_inc(chunk_t data, uint16_t checksum) { - u_int32_t sum = ntohs((u_int16_t)~checksum); + uint32_t sum = ntohs((uint16_t)~checksum); while (data.len > 1) { @@ -1001,7 +1001,7 @@ u_int16_t chunk_internet_checksum_inc(chunk_t data, u_int16_t checksum) } if (data.len) { - sum += (u_int16_t)*data.ptr << 8; + sum += (uint16_t)*data.ptr << 8; } while (sum >> 16) { @@ -1013,7 +1013,7 @@ u_int16_t chunk_internet_checksum_inc(chunk_t data, u_int16_t checksum) /** * Described in header. */ -u_int16_t chunk_internet_checksum(chunk_t data) +uint16_t chunk_internet_checksum(chunk_t data) { return chunk_internet_checksum_inc(data, 0xffff); } diff --git a/src/libstrongswan/utils/chunk.h b/src/libstrongswan/utils/chunk.h index 2ec7f7543..160d09944 100644 --- a/src/libstrongswan/utils/chunk.h +++ b/src/libstrongswan/utils/chunk.h @@ -280,11 +280,11 @@ static inline chunk_t chunk_skip(chunk_t chunk, size_t bytes) } /** - * Skip a leading zero-valued byte + * Skip any leading zero-valued bytes */ static inline chunk_t chunk_skip_zero(chunk_t chunk) { - if (chunk.len > 1 && *chunk.ptr == 0x00) + while (chunk.len > 1 && *chunk.ptr == 0x00) { chunk.ptr++; chunk.len--; @@ -375,7 +375,7 @@ void chunk_hash_seed(); * @param chunk data to hash * @return hash value */ -u_int32_t chunk_hash(chunk_t chunk); +uint32_t chunk_hash(chunk_t chunk); /** * Incremental version of chunk_hash. Use this to hash two or more chunks. @@ -384,7 +384,7 @@ u_int32_t chunk_hash(chunk_t chunk); * @param hash previous hash value * @return hash value */ -u_int32_t chunk_hash_inc(chunk_t chunk, u_int32_t hash); +uint32_t chunk_hash_inc(chunk_t chunk, uint32_t hash); /** * Computes a 32 bit hash of the given chunk. @@ -398,7 +398,7 @@ u_int32_t chunk_hash_inc(chunk_t chunk, u_int32_t hash); * @param chunk data to hash * @return hash value */ -u_int32_t chunk_hash_static(chunk_t chunk); +uint32_t chunk_hash_static(chunk_t chunk); /** * Incremental version of chunk_hash_static(). Use this to hash two or more @@ -408,7 +408,7 @@ u_int32_t chunk_hash_static(chunk_t chunk); * @param hash previous hash value * @return hash value */ -u_int32_t chunk_hash_static_inc(chunk_t chunk, u_int32_t hash); +uint32_t chunk_hash_static_inc(chunk_t chunk, uint32_t hash); /** * Computes a quick MAC from the given chunk and key using SipHash. @@ -422,7 +422,7 @@ u_int32_t chunk_hash_static_inc(chunk_t chunk, u_int32_t hash); * @param key key to use * @return MAC for given input and key */ -u_int64_t chunk_mac(chunk_t chunk, u_char *key); +uint64_t chunk_mac(chunk_t chunk, u_char *key); /** * Calculate the Internet Checksum according to RFC 1071 for the given chunk. @@ -434,7 +434,7 @@ u_int64_t chunk_mac(chunk_t chunk, u_char *key); * @param data data to process * @return checksum (one's complement, network order) */ -u_int16_t chunk_internet_checksum(chunk_t data); +uint16_t chunk_internet_checksum(chunk_t data); /** * Extend the given Internet Checksum (one's complement, in network byte order) @@ -447,7 +447,7 @@ u_int16_t chunk_internet_checksum(chunk_t data); * @param checksum previous checksum (one's complement, network order) * @return checksum (one's complement, network order) */ -u_int16_t chunk_internet_checksum_inc(chunk_t data, u_int16_t checksum); +uint16_t chunk_internet_checksum_inc(chunk_t data, uint16_t checksum); /** * printf hook function for chunk_t. diff --git a/src/libstrongswan/utils/compat/android.h b/src/libstrongswan/utils/compat/android.h index b3ea9c475..6edd3effb 100644 --- a/src/libstrongswan/utils/compat/android.h +++ b/src/libstrongswan/utils/compat/android.h @@ -21,6 +21,8 @@ #ifndef ANDROID_H_ #define ANDROID_H_ +#include <android/api-level.h> + /* stuff defined in AndroidConfig.h, which is included using the -include * command-line option, thus cannot be undefined using -U CFLAGS options. * the reason we have to undefine these flags in the first place, is that @@ -28,4 +30,19 @@ * actually defined. */ #undef HAVE_BACKTRACE +/* API level 21 changed quite a few things, we define some stuff here and not + * via CFLAGS in Android.mk files as it is easier to compare versions */ +#if __ANDROID_API__ >= 21 + +#define HAVE_PTHREAD_CONDATTR_INIT 1 +#define HAVE_CONDATTR_CLOCK_MONOTONIC 1 + +#define HAVE_SYS_CAPABILITY_H 1 + +#else /* __ANDROID_API__ */ + +#define HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC 1 + +#endif /* __ANDROID_API__ */ + #endif /** ANDROID_H_ @}*/ diff --git a/src/libstrongswan/utils/cpu_feature.c b/src/libstrongswan/utils/cpu_feature.c index d86ca6bd8..0529701ea 100644 --- a/src/libstrongswan/utils/cpu_feature.c +++ b/src/libstrongswan/utils/cpu_feature.c @@ -102,7 +102,7 @@ static cpu_feature_t get_via_features() */ cpu_feature_t cpu_feature_get_all() { - char vendor[3 * sizeof(u_int32_t) + 1]; + char vendor[3 * sizeof(uint32_t) + 1]; cpu_feature_t f = 0; u_int a, b, c, d; diff --git a/src/libstrongswan/utils/identification.c b/src/libstrongswan/utils/identification.c index 2b2e907f0..384bd6c92 100644 --- a/src/libstrongswan/utils/identification.c +++ b/src/libstrongswan/utils/identification.c @@ -80,6 +80,7 @@ static const x501rdn_t x501rdns[] = { {"G", OID_GIVEN_NAME, ASN1_PRINTABLESTRING}, {"I", OID_INITIALS, ASN1_PRINTABLESTRING}, {"dnQualifier", OID_DN_QUALIFIER, ASN1_PRINTABLESTRING}, + {"dmdName", OID_DMD_NAME, ASN1_PRINTABLESTRING}, {"pseudonym", OID_PSEUDONYM, ASN1_PRINTABLESTRING}, {"ID", OID_UNIQUE_IDENTIFIER, ASN1_PRINTABLESTRING}, {"EN", OID_EMPLOYEE_NUMBER, ASN1_PRINTABLESTRING}, @@ -220,6 +221,7 @@ METHOD(enumerator_t, rdn_part_enumerate, bool, {OID_GIVEN_NAME, ID_PART_RDN_G}, {OID_INITIALS, ID_PART_RDN_I}, {OID_DN_QUALIFIER, ID_PART_RDN_DNQ}, + {OID_DMD_NAME, ID_PART_RDN_DMDN}, {OID_PSEUDONYM, ID_PART_RDN_PN}, {OID_UNIQUE_IDENTIFIER, ID_PART_RDN_ID}, {OID_EMAIL_ADDRESS, ID_PART_RDN_E}, @@ -727,7 +729,8 @@ METHOD(identification_t, equals_strcasecmp, bool, /* we do some extra sanity checks to check for invalid IDs with a * terminating null in it. */ - if (this->encoded.len == encoded.len && + if (this->type == other->get_type(other) && + this->encoded.len == encoded.len && memchr(this->encoded.ptr, 0, this->encoded.len) == NULL && memchr(encoded.ptr, 0, encoded.len) == NULL && strncasecmp(this->encoded.ptr, encoded.ptr, this->encoded.len) == 0) @@ -1152,15 +1155,15 @@ static private_identification_t *identification_create(id_type_t type) { case ID_ANY: this->public.hash = _hash_binary; - this->public.matches = _matches_any; this->public.equals = _equals_binary; + this->public.matches = _matches_any; this->public.contains_wildcards = return_true; break; case ID_FQDN: case ID_RFC822_ADDR: this->public.hash = _hash_binary; - this->public.matches = _matches_string; this->public.equals = _equals_strcasecmp; + this->public.matches = _matches_string; this->public.contains_wildcards = _contains_wildcards_memchr; break; case ID_DER_ASN1_DN: diff --git a/src/libstrongswan/utils/identification.h b/src/libstrongswan/utils/identification.h index 51d132491..206f7c3e0 100644 --- a/src/libstrongswan/utils/identification.h +++ b/src/libstrongswan/utils/identification.h @@ -168,6 +168,8 @@ enum id_part_t { ID_PART_RDN_I, /** DN Qualifier RDN of a DN */ ID_PART_RDN_DNQ, + /** dmdName RDN of a DN */ + ID_PART_RDN_DMDN, /** Pseudonym RDN of a DN */ ID_PART_RDN_PN, /** UniqueIdentifier RDN of a DN */ diff --git a/src/libstrongswan/utils/integrity_checker.c b/src/libstrongswan/utils/integrity_checker.c index b66df02e7..6f9510b3e 100644 --- a/src/libstrongswan/utils/integrity_checker.c +++ b/src/libstrongswan/utils/integrity_checker.c @@ -56,10 +56,10 @@ struct private_integrity_checker_t { int checksum_count; }; -METHOD(integrity_checker_t, build_file, u_int32_t, +METHOD(integrity_checker_t, build_file, uint32_t, private_integrity_checker_t *this, char *file, size_t *len) { - u_int32_t checksum; + uint32_t checksum; chunk_t *contents; contents = chunk_map(file, FALSE); @@ -109,7 +109,7 @@ static int callback(struct dl_phdr_info *dlpi, size_t size, Dl_info *dli) return 0; } -METHOD(integrity_checker_t, build_segment, u_int32_t, +METHOD(integrity_checker_t, build_segment, uint32_t, private_integrity_checker_t *this, void *sym, size_t *len) { chunk_t segment; @@ -154,7 +154,7 @@ METHOD(integrity_checker_t, check_file, bool, private_integrity_checker_t *this, char *name, char *file) { integrity_checksum_t *cs; - u_int32_t sum; + uint32_t sum; size_t len = 0; cs = find_checksum(this, name); @@ -188,7 +188,7 @@ METHOD(integrity_checker_t, check_segment, bool, private_integrity_checker_t *this, char *name, void *sym) { integrity_checksum_t *cs; - u_int32_t sum; + uint32_t sum; size_t len = 0; cs = find_checksum(this, name); diff --git a/src/libstrongswan/utils/integrity_checker.h b/src/libstrongswan/utils/integrity_checker.h index afaa114b3..2ac21c608 100644 --- a/src/libstrongswan/utils/integrity_checker.h +++ b/src/libstrongswan/utils/integrity_checker.h @@ -35,11 +35,11 @@ struct integrity_checksum_t { /* size in bytes of the file on disk */ size_t file_len; /* checksum of the file on disk */ - u_int32_t file; + uint32_t file; /* size in bytes of executable segment in memory */ size_t segment_len; /* checksum of the executable segment in memory */ - u_int32_t segment; + uint32_t segment; }; /** @@ -66,7 +66,7 @@ struct integrity_checker_t { * @param len return length in bytes of file * @return checksum, 0 on error */ - u_int32_t (*build_file)(integrity_checker_t *this, char *file, size_t *len); + uint32_t (*build_file)(integrity_checker_t *this, char *file, size_t *len); /** * Check the integrity of the code segment in memory. @@ -83,7 +83,7 @@ struct integrity_checker_t { * @param len return length in bytes of code segment in memory * @return checksum, 0 on error */ - u_int32_t (*build_segment)(integrity_checker_t *this, void *sym, size_t *len); + uint32_t (*build_segment)(integrity_checker_t *this, void *sym, size_t *len); /** * Check both, on disk file integrity and loaded segment. diff --git a/src/libstrongswan/utils/leak_detective.c b/src/libstrongswan/utils/leak_detective.c index 99f4843ad..d0f646c31 100644 --- a/src/libstrongswan/utils/leak_detective.c +++ b/src/libstrongswan/utils/leak_detective.c @@ -120,17 +120,17 @@ struct memory_header_t { /** * Padding to make sizeof(memory_header_t) == 32 */ - u_int32_t padding[sizeof(void*) == sizeof(u_int32_t) ? 3 : 0]; + uint32_t padding[sizeof(void*) == sizeof(uint32_t) ? 3 : 0]; /** * Number of bytes following after the header */ - u_int32_t bytes; + uint32_t bytes; /** * magic bytes to detect bad free or heap underflow, MEMORY_HEADER_MAGIC */ - u_int32_t magic; + uint32_t magic; }__attribute__((__packed__)); @@ -142,7 +142,7 @@ struct memory_tail_t { /** * Magic bytes to detect heap overflow, MEMORY_TAIL_MAGIC */ - u_int32_t magic; + uint32_t magic; }__attribute__((__packed__)); @@ -522,6 +522,7 @@ char *whitelist[] = { "vsyslog", "__syslog_chk", "__vsyslog_chk", + "__fprintf_chk", "getaddrinfo", "setlocale", "getpass", @@ -532,6 +533,7 @@ char *whitelist[] = { "getpwuid_r", "initgroups", "tzset", + "_IO_file_doallocate", /* ignore dlopen, as we do not dlclose to get proper leak reports */ "dlopen", "dlerror", @@ -562,6 +564,10 @@ char *whitelist[] = { "ECDSA_do_sign_ex", "ECDSA_verify", "RSA_new_method", + /* OpenSSL 1.1.0 does not cleanup anymore until the library is unloaded */ + "OPENSSL_init_crypto", + "CRYPTO_THREAD_lock_new", + "ERR_add_error_data", /* OpenSSL libssl */ "SSL_COMP_get_compression_methods", /* NSPR */ @@ -808,10 +814,11 @@ HOOK(void*, malloc, size_t bytes) HOOK(void*, calloc, size_t nmemb, size_t size) { void *ptr; + volatile size_t total; - size *= nmemb; - ptr = malloc(size); - memset(ptr, 0, size); + total = nmemb * size; + ptr = malloc(total); + memset(ptr, 0, total); return ptr; } @@ -837,6 +844,18 @@ HOOK(void, free, void *ptr) if (!enabled || thread_disabled->get(thread_disabled)) { + /* after deinitialization we might have to free stuff we allocated + * while we were enabled */ + if (!first_header.magic && ptr) + { + hdr = ptr - sizeof(memory_header_t); + tail = ptr + hdr->bytes; + if (hdr->magic == MEMORY_HEADER_MAGIC && + tail->magic == MEMORY_TAIL_MAGIC) + { + ptr = hdr; + } + } real_free(ptr); return; } @@ -953,6 +972,7 @@ METHOD(leak_detective_t, destroy, void, lock->destroy(lock); thread_disabled->destroy(thread_disabled); free(this); + first_header.magic = 0; first_header.next = NULL; } diff --git a/src/libstrongswan/utils/utils.c b/src/libstrongswan/utils/utils.c index 40cb43d90..4deba0fe7 100644 --- a/src/libstrongswan/utils/utils.c +++ b/src/libstrongswan/utils/utils.c @@ -33,7 +33,7 @@ /* This is from the kernel sources. We limit the length of directory names to * 256 as we only use it to enumerate FDs. */ struct linux_dirent64 { - u_int64_t d_ino; + uint64_t d_ino; int64_t d_off; unsigned short d_reclen; unsigned char d_type; diff --git a/src/libstrongswan/utils/utils/align.c b/src/libstrongswan/utils/utils/align.c index 29f110ff1..ffdb1b5ce 100644 --- a/src/libstrongswan/utils/utils/align.c +++ b/src/libstrongswan/utils/utils/align.c @@ -20,9 +20,9 @@ /** * Described in header. */ -void* malloc_align(size_t size, u_int8_t align) +void* malloc_align(size_t size, uint8_t align) { - u_int8_t pad; + uint8_t pad; void *ptr; if (align == 0) @@ -46,7 +46,7 @@ void* malloc_align(size_t size, u_int8_t align) */ void free_align(void *ptr) { - u_int8_t pad, *pos; + uint8_t pad, *pos; pos = ptr - 1; /* verify padding to check any corruption */ diff --git a/src/libstrongswan/utils/utils/align.h b/src/libstrongswan/utils/utils/align.h index 39cde10c8..a28dc3668 100644 --- a/src/libstrongswan/utils/utils/align.h +++ b/src/libstrongswan/utils/utils/align.h @@ -74,7 +74,7 @@ static inline size_t round_down(size_t size, size_t alignment) * @param align alignment, up to 255 bytes, usually a power of 2 * @return allocated hunk, aligned to align bytes */ -void* malloc_align(size_t size, u_int8_t align); +void* malloc_align(size_t size, uint8_t align); /** * Free a hunk allocated by malloc_align(). diff --git a/src/libstrongswan/utils/utils/byteorder.h b/src/libstrongswan/utils/utils/byteorder.h index 3ccbad5f1..7c7e53420 100644 --- a/src/libstrongswan/utils/utils/byteorder.h +++ b/src/libstrongswan/utils/utils/byteorder.h @@ -26,7 +26,7 @@ * Architecture independent bitfield definition helpers (at least with GCC). * * Defines a bitfield with a type t and a fixed size of bitfield members, e.g.: - * BITFIELD2(u_int8_t, + * BITFIELD2(uint8_t, * low: 4, * high: 4, * ) flags; @@ -47,9 +47,14 @@ #ifndef le32toh # if BYTE_ORDER == BIG_ENDIAN # define le32toh(x) __builtin_bswap32(x) -# define htole32(x) __builtin_bswap32(x) # else # define le32toh(x) (x) +# endif +#endif +#ifndef htole32 +# if BYTE_ORDER == BIG_ENDIAN +# define htole32(x) __builtin_bswap32(x) +# else # define htole32(x) (x) # endif #endif @@ -57,9 +62,14 @@ #ifndef le64toh # if BYTE_ORDER == BIG_ENDIAN # define le64toh(x) __builtin_bswap64(x) -# define htole64(x) __builtin_bswap64(x) # else # define le64toh(x) (x) +# endif +#endif +#ifndef htole64 +# if BYTE_ORDER == BIG_ENDIAN +# define htole64(x) __builtin_bswap64(x) +# else # define htole64(x) (x) # endif #endif @@ -67,9 +77,14 @@ #ifndef be64toh # if BYTE_ORDER == BIG_ENDIAN # define be64toh(x) (x) -# define htobe64(x) (x) # else # define be64toh(x) __builtin_bswap64(x) +# endif +#endif +#ifndef htobe64 +# if BYTE_ORDER == BIG_ENDIAN +# define htobe64(x) (x) +# else # define htobe64(x) __builtin_bswap64(x) # endif #endif @@ -80,7 +95,7 @@ * @param host host order 16-bit value * @param network unaligned address to write network order value to */ -static inline void htoun16(void *network, u_int16_t host) +static inline void htoun16(void *network, uint16_t host) { char *unaligned = (char*)network; @@ -94,7 +109,7 @@ static inline void htoun16(void *network, u_int16_t host) * @param host host order 32-bit value * @param network unaligned address to write network order value to */ -static inline void htoun32(void *network, u_int32_t host) +static inline void htoun32(void *network, uint32_t host) { char *unaligned = (char*)network; @@ -108,7 +123,7 @@ static inline void htoun32(void *network, u_int32_t host) * @param host host order 64-bit value * @param network unaligned address to write network order value to */ -static inline void htoun64(void *network, u_int64_t host) +static inline void htoun64(void *network, uint64_t host) { char *unaligned = (char*)network; @@ -122,10 +137,10 @@ static inline void htoun64(void *network, u_int64_t host) * @param network unaligned address to read network order value from * @return host order value */ -static inline u_int16_t untoh16(void *network) +static inline uint16_t untoh16(void *network) { char *unaligned = (char*)network; - u_int16_t tmp; + uint16_t tmp; memcpy(&tmp, unaligned, sizeof(tmp)); return ntohs(tmp); @@ -137,10 +152,10 @@ static inline u_int16_t untoh16(void *network) * @param network unaligned address to read network order value from * @return host order value */ -static inline u_int32_t untoh32(void *network) +static inline uint32_t untoh32(void *network) { char *unaligned = (char*)network; - u_int32_t tmp; + uint32_t tmp; memcpy(&tmp, unaligned, sizeof(tmp)); return ntohl(tmp); @@ -152,10 +167,10 @@ static inline u_int32_t untoh32(void *network) * @param network unaligned address to read network order value from * @return host order value */ -static inline u_int64_t untoh64(void *network) +static inline uint64_t untoh64(void *network) { char *unaligned = (char*)network; - u_int64_t tmp; + uint64_t tmp; memcpy(&tmp, unaligned, sizeof(tmp)); return be64toh(tmp); @@ -167,9 +182,9 @@ static inline u_int64_t untoh64(void *network) * @param p unaligned address to read little endian value from * @return host order value */ -static inline u_int32_t uletoh32(void *p) +static inline uint32_t uletoh32(void *p) { - u_int32_t ret; + uint32_t ret; memcpy(&ret, p, sizeof(ret)); ret = le32toh(ret); @@ -182,7 +197,7 @@ static inline u_int32_t uletoh32(void *p) * @param p host order 32-bit value * @param v unaligned address to write little endian value to */ -static inline void htoule32(void *p, u_int32_t v) +static inline void htoule32(void *p, uint32_t v) { v = htole32(v); memcpy(p, &v, sizeof(v)); diff --git a/src/libstrongswan/utils/utils/memory.c b/src/libstrongswan/utils/utils/memory.c index a15371518..30c6f546c 100644 --- a/src/libstrongswan/utils/utils/memory.c +++ b/src/libstrongswan/utils/utils/memory.c @@ -20,7 +20,7 @@ /** * Described in header. */ -void memxor(u_int8_t dst[], u_int8_t src[], size_t n) +void memxor(uint8_t dst[], uint8_t src[], size_t n) { int m, i; diff --git a/src/libstrongswan/utils/utils/memory.h b/src/libstrongswan/utils/utils/memory.h index aef318f6c..b978e7c48 100644 --- a/src/libstrongswan/utils/utils/memory.h +++ b/src/libstrongswan/utils/utils/memory.h @@ -80,7 +80,7 @@ static inline void *memset_noop(void *s, int c, size_t n) /** * Same as memcpy, but XORs src into dst instead of copy */ -void memxor(u_int8_t dest[], u_int8_t src[], size_t n); +void memxor(uint8_t dest[], uint8_t src[], size_t n); /** * Safely overwrite n bytes of memory at ptr with zero, non-inlining variant. diff --git a/src/libstrongswan/utils/utils/string.h b/src/libstrongswan/utils/utils/string.h index 60eaaae22..562516b91 100644 --- a/src/libstrongswan/utils/utils/string.h +++ b/src/libstrongswan/utils/utils/string.h @@ -27,7 +27,7 @@ */ static inline bool streq(const char *x, const char *y) { - return strcmp(x, y) == 0; + return (x == y) || (x && y && strcmp(x, y) == 0); } /** @@ -35,7 +35,7 @@ static inline bool streq(const char *x, const char *y) */ static inline bool strneq(const char *x, const char *y, size_t len) { - return strncmp(x, y, len) == 0; + return (x == y) || (x && y && strncmp(x, y, len) == 0); } /** @@ -51,7 +51,7 @@ static inline bool strpfx(const char *x, const char *prefix) */ static inline bool strcaseeq(const char *x, const char *y) { - return strcasecmp(x, y) == 0; + return (x == y) || (x && y && strcasecmp(x, y) == 0); } /** @@ -59,7 +59,7 @@ static inline bool strcaseeq(const char *x, const char *y) */ static inline bool strncaseeq(const char *x, const char *y, size_t len) { - return strncasecmp(x, y, len) == 0; + return (x == y) || (x && y && strncasecmp(x, y, len) == 0); } /** diff --git a/src/libstrongswan/utils/utils/time.c b/src/libstrongswan/utils/utils/time.c index c67ae93f2..48e5151c0 100644 --- a/src/libstrongswan/utils/utils/time.c +++ b/src/libstrongswan/utils/utils/time.c @@ -121,7 +121,7 @@ int time_delta_printf_hook(printf_hook_data_t *data, printf_hook_spec_t *spec, char* unit = "second"; time_t *arg1 = *((time_t**)(args[0])); time_t *arg2 = *((time_t**)(args[1])); - u_int64_t delta = llabs(*arg1 - *arg2); + uint64_t delta = llabs(*arg1 - *arg2); if (delta > 2 * 60 * 60 * 24) { diff --git a/src/libstrongswan/utils/utils/types.h b/src/libstrongswan/utils/utils/types.h index 056c2e0c2..45b5043bf 100644 --- a/src/libstrongswan/utils/utils/types.h +++ b/src/libstrongswan/utils/utils/types.h @@ -43,19 +43,6 @@ # define TRUE true #endif /* TRUE */ -/** - * define some missing fixed width int types on OpenSolaris. - * TODO: since the uintXX_t types are defined by the C99 standard we should - * probably use those anyway - */ -#if defined __sun || defined WIN32 -#include <stdint.h> -typedef uint8_t u_int8_t; -typedef uint16_t u_int16_t; -typedef uint32_t u_int32_t; -typedef uint64_t u_int64_t; -#endif - #ifdef HAVE_INT128 /** * 128 bit wide signed integer, if supported @@ -70,7 +57,7 @@ typedef unsigned __int128 u_int128_t; # define MAX_UINT_TYPE u_int128_t #else # define MAX_INT_TYPE int64_t -# define MAX_UINT_TYPE u_int64_t +# define MAX_UINT_TYPE uint64_t #endif /** |