From dc21e28e1fa29202977344cea2bd86a3fba755c6 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Tue, 22 Jan 2019 17:35:53 -0800 Subject: [PATCH] Fix parsing XOR-MAPPED-ADDRESS if the optional comprehension bit is set --- src/SimpleStun.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/SimpleStun.c b/src/SimpleStun.c index f4b256d..3867fa1 100644 --- a/src/SimpleStun.c +++ b/src/SimpleStun.c @@ -133,7 +133,8 @@ int LiFindExternalAddressIP4(const char* stunServer, unsigned short stunPort, un Limelog("STUN attribute out of bounds: %d\n", htons(attribute->length)); return -5; } - else if (htons(attribute->type) != STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS) { + // Mask off the comprehension bit + else if ((htons(attribute->type) & 0x7FFF) != STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS) { // Continue searching if this wasn't our address bytesRead -= sizeof(*attribute) + htons(attribute->length); attribute = (PSTUN_ATTRIBUTE_HEADER)(((char*)attribute) + sizeof(*attribute) + htons(attribute->length));