From 60b391e2a55749c0cf9e96f53515673a0898a0d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Sun, 15 Feb 2015 10:24:20 +0000 Subject: Facebook: Fix for infinite channel "starting"; Version bump This fixes it by better using of random number generator. Now we use rand_s() instead of rand() because of thread safety and also we have random "seed" per each facebook_client with much better initial random seed. Previously when user logged off and then logged in again, it used same randomgly generated clientid which resulted in confusion on Facebook server and "infinite" repeated requests for channel every second from Miranda... This bug was here probably for many months and affected all stable and development versions. git-svn-id: http://svn.miranda-ng.org/main/trunk@12119 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/FacebookRM/src/utils.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'protocols/FacebookRM/src/utils.cpp') diff --git a/protocols/FacebookRM/src/utils.cpp b/protocols/FacebookRM/src/utils.cpp index 8c388f738c..f277103203 100644 --- a/protocols/FacebookRM/src/utils.cpp +++ b/protocols/FacebookRM/src/utils.cpp @@ -456,19 +456,26 @@ std::string utils::text::source_get_form_data(std::string* data) return values; } -std::string utils::text::rand_string(int len, const char *chars) +std::string utils::text::rand_string(int len, const char *chars, unsigned int *number) { std::stringstream out; int strLen = (int)strlen(chars); for (int i = 0; i < len; ++i) { - out << chars[utils::number::random(0, strLen)]; + out << chars[utils::number::random(0, strLen, number)]; } return out.str(); } -int utils::number::random(int min, int max) +int utils::number::random(int min, int max, unsigned int *number) { + if (number != NULL) { + errno_t err = rand_s(number); + if (!err) + return (*number % (max - min)) + min; + } + + // If called didn't specified "number" or there was error, fallback to rand() return (rand() % (max - min)) + min; } -- cgit v1.2.3