]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
chunk: Fix internet checksum calculation on big-endian systems
authorTobias Brunner <tobias@strongswan.org>
Wed, 22 Oct 2014 17:41:40 +0000 (19:41 +0200)
committerTobias Brunner <tobias@strongswan.org>
Thu, 23 Oct 2014 09:13:28 +0000 (11:13 +0200)
ntohs() might be defined as noop (#define ntohs(x) (x)) so we have
to manually shorten the negated value (gets promoted to an int).

Fixes #747.

src/libstrongswan/utils/chunk.c

index 4b24b37c25b03f2c8d9be78021832444fb74c357..c4471be707302d699c01fe531152631eed9494e7 100644 (file)
@@ -992,7 +992,7 @@ u_int32_t chunk_hash_static(chunk_t chunk)
  */
 u_int16_t chunk_internet_checksum_inc(chunk_t data, u_int16_t checksum)
 {
-       u_int32_t sum = ntohs(~checksum);
+       u_int32_t sum = ntohs((u_int16_t)~checksum);
 
        while (data.len > 1)
        {