summaryrefslogtreecommitdiff
path: root/stun
diff options
context:
space:
mode:
authorYouness Alaoui <youness.alaoui@collabora.co.uk>2009-03-05 15:19:54 -0500
committerYouness Alaoui <youness.alaoui@collabora.co.uk>2009-03-05 15:19:54 -0500
commit3b935de921628f238be0c0490d061ebb253aae80 (patch)
treeb22431365f909d2ee3105514ed67e278d634d491 /stun
parentd73a8654ee7d2e5bcaa3e6f2dfc82ad5d2619f89 (diff)
downloadlibnice-3b935de921628f238be0c0490d061ebb253aae80.tar.gz
Fix the stupid wlm2009 crc32 typo without using a global variable
Diffstat (limited to 'stun')
-rw-r--r--stun/stun5389.c5
-rw-r--r--stun/stun5389.h3
-rw-r--r--stun/stunagent.c17
-rw-r--r--stun/stuncrc32.c4
-rw-r--r--stun/stuncrc32.h4
5 files changed, 12 insertions, 21 deletions
diff --git a/stun/stun5389.c b/stun/stun5389.c
index a515387..b28fa71 100644
--- a/stun/stun5389.c
+++ b/stun/stun5389.c
@@ -52,7 +52,8 @@
#include "stuncrc32.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];
uint16_t fakelen = htons (len - 20u);
@@ -67,7 +68,7 @@ uint32_t stun_fingerprint (const uint8_t *msg, size_t len)
/* first 4 bytes done, last 8 bytes not summed */
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)
diff --git a/stun/stun5389.h b/stun/stun5389.h
index 3aa357b..1b90b99 100644
--- a/stun/stun5389.h
+++ b/stun/stun5389.h
@@ -57,7 +57,8 @@
*
* @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:
diff --git a/stun/stunagent.c b/stun/stunagent.c
index a940d81..d904622 100644
--- a/stun/stunagent.c
+++ b/stun/stunagent.c
@@ -145,14 +145,9 @@ StunValidationStatus stun_agent_validate (StunAgent *agent, StunMessage *msg,
stun_debug ("STUN demux error: no FINGERPRINT attribute!\n");
return STUN_VALIDATION_BAD_REQUEST;
}
-
- if (agent->compatibility == STUN_COMPATIBILITY_WLM2009)
- wlm2009_stupid_crc32_typo = 1;
- else
- wlm2009_stupid_crc32_typo = 0;
-
/* 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);
if (fpr != crc32) {
stun_debug ("STUN demux error: bad fingerprint: 0x%08x,"
@@ -578,12 +573,8 @@ size_t stun_agent_finish_message (StunAgent *agent, StunMessage *msg,
return 0;
}
-
- if (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));
+ fpr = stun_fingerprint (msg->buffer, stun_message_length (msg),
+ agent->compatibility == STUN_COMPATIBILITY_WLM2009);
memcpy (ptr, &fpr, sizeof (fpr));
stun_debug (" Message HMAC-SHA1 fingerprint: ");
diff --git a/stun/stuncrc32.c b/stun/stuncrc32.c
index 0f3fa66..5bfcd03 100644
--- a/stun/stuncrc32.c
+++ b/stun/stuncrc32.c
@@ -89,8 +89,6 @@
#include "stuncrc32.h"
-int wlm2009_stupid_crc32_typo = 0;
-
static const uint32_t crc32_tab[] = {
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
@@ -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;
uint32_t crc = 0xffffffff;
diff --git a/stun/stuncrc32.h b/stun/stuncrc32.h
index 0ebd2c2..be1fedd 100644
--- a/stun/stuncrc32.h
+++ b/stun/stuncrc32.h
@@ -43,6 +43,7 @@
#include "win32_common.h"
#else
#include <stdint.h>
+#include <stdbool.h>
#endif
#include <stdlib.h>
@@ -53,7 +54,6 @@ typedef struct {
} crc_data;
-int wlm2009_stupid_crc32_typo;
-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);
#endif /* _CRC32_H */