Commit 3b935de9 authored by Youness Alaoui's avatar Youness Alaoui

Fix the stupid wlm2009 crc32 typo without using a global variable

parent d73a8654
...@@ -52,7 +52,8 @@ ...@@ -52,7 +52,8 @@
#include "stuncrc32.h" #include "stuncrc32.h"
#include "stunmessage.h" #include "stunmessage.h"
uint32_t stun_fingerprint (const uint8_t *msg, size_t len) uint32_t stun_fingerprint (const uint8_t *msg, size_t len,
bool wlm2009_stupid_crc32_typo)
{ {
crc_data data[3]; crc_data data[3];
uint16_t fakelen = htons (len - 20u); uint16_t fakelen = htons (len - 20u);
...@@ -67,7 +68,7 @@ uint32_t stun_fingerprint (const uint8_t *msg, size_t len) ...@@ -67,7 +68,7 @@ uint32_t stun_fingerprint (const uint8_t *msg, size_t len)
/* first 4 bytes done, last 8 bytes not summed */ /* first 4 bytes done, last 8 bytes not summed */
data[2].len = len - 12u; data[2].len = len - 12u;
return htonl (crc32 (data, 3) ^ 0x5354554e); return htonl (crc32 (data, 3, wlm2009_stupid_crc32_typo) ^ 0x5354554e);
} }
bool stun_message_has_cookie (const StunMessage *msg) bool stun_message_has_cookie (const StunMessage *msg)
......
...@@ -57,7 +57,8 @@ ...@@ -57,7 +57,8 @@
* *
* @return fingerprint value in <b>host</b> byte order. * @return fingerprint value in <b>host</b> byte order.
*/ */
uint32_t stun_fingerprint (const uint8_t *msg, size_t len); uint32_t stun_fingerprint (const uint8_t *msg, size_t len,
bool wlm2009_stupid_crc32_typo);
/** /**
* stun_message_has_cookie: * stun_message_has_cookie:
......
...@@ -145,14 +145,9 @@ StunValidationStatus stun_agent_validate (StunAgent *agent, StunMessage *msg, ...@@ -145,14 +145,9 @@ StunValidationStatus stun_agent_validate (StunAgent *agent, StunMessage *msg,
stun_debug ("STUN demux error: no FINGERPRINT attribute!\n"); stun_debug ("STUN demux error: no FINGERPRINT attribute!\n");
return STUN_VALIDATION_BAD_REQUEST; return STUN_VALIDATION_BAD_REQUEST;
} }
if (agent->compatibility == STUN_COMPATIBILITY_WLM2009)
wlm2009_stupid_crc32_typo = 1;
else
wlm2009_stupid_crc32_typo = 0;
/* Checks FINGERPRINT */ /* Checks FINGERPRINT */
crc32 = stun_fingerprint (msg->buffer, stun_message_length (msg)); crc32 = stun_fingerprint (msg->buffer, stun_message_length (msg),
agent->compatibility == STUN_COMPATIBILITY_WLM2009);
fpr = ntohl (fpr); fpr = ntohl (fpr);
if (fpr != crc32) { if (fpr != crc32) {
stun_debug ("STUN demux error: bad fingerprint: 0x%08x," stun_debug ("STUN demux error: bad fingerprint: 0x%08x,"
...@@ -578,12 +573,8 @@ size_t stun_agent_finish_message (StunAgent *agent, StunMessage *msg, ...@@ -578,12 +573,8 @@ size_t stun_agent_finish_message (StunAgent *agent, StunMessage *msg,
return 0; return 0;
} }
fpr = stun_fingerprint (msg->buffer, stun_message_length (msg),
if (agent->compatibility == STUN_COMPATIBILITY_WLM2009) agent->compatibility == STUN_COMPATIBILITY_WLM2009);
wlm2009_stupid_crc32_typo = 1;
else
wlm2009_stupid_crc32_typo = 0;
fpr = stun_fingerprint (msg->buffer, stun_message_length (msg));
memcpy (ptr, &fpr, sizeof (fpr)); memcpy (ptr, &fpr, sizeof (fpr));
stun_debug (" Message HMAC-SHA1 fingerprint: "); stun_debug (" Message HMAC-SHA1 fingerprint: ");
......
...@@ -89,8 +89,6 @@ ...@@ -89,8 +89,6 @@
#include "stuncrc32.h" #include "stuncrc32.h"
int wlm2009_stupid_crc32_typo = 0;
static const uint32_t crc32_tab[] = { static const uint32_t crc32_tab[] = {
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
...@@ -138,7 +136,7 @@ static const uint32_t crc32_tab[] = { ...@@ -138,7 +136,7 @@ static const uint32_t crc32_tab[] = {
}; };
uint32_t crc32 (const crc_data *data, size_t n) uint32_t crc32 (const crc_data *data, size_t n, bool wlm2009_stupid_crc32_typo)
{ {
size_t i; size_t i;
uint32_t crc = 0xffffffff; uint32_t crc = 0xffffffff;
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include "win32_common.h" #include "win32_common.h"
#else #else
#include <stdint.h> #include <stdint.h>
#include <stdbool.h>
#endif #endif
#include <stdlib.h> #include <stdlib.h>
...@@ -53,7 +54,6 @@ typedef struct { ...@@ -53,7 +54,6 @@ typedef struct {
} crc_data; } crc_data;
int wlm2009_stupid_crc32_typo; uint32_t crc32 (const crc_data *data, size_t n, bool wlm2009_stupid_crc32_typo);
uint32_t crc32 (const crc_data *data, size_t n);
#endif /* _CRC32_H */ #endif /* _CRC32_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment