QW-Group / mvdsv

MVDSV: a QuakeWorld server
GNU General Public License v2.0
58 stars 56 forks source link

BUG: fix rcon_crypt for any size of time_t #112

Open VVD opened 1 year ago

VVD commented 1 year ago
diff --git a/src/common.h b/src/common.h
index 0bece51..a5999d0 100644
--- a/src/common.h
+++ b/src/common.h
@@ -231,4 +231,6 @@ qbool COM_FileExists(char *path);
 // Name comparison: case insensitive, red/white text insensitive
 int Q_namecmp(const char* s1, const char* s2);

+#define TIME_T_SIZE    8
+
 #endif /* !__COMMON_H__ */
diff --git a/src/sv_main.c b/src/sv_main.c
index 9629d9d..50091d5 100644
--- a/src/sv_main.c
+++ b/src/sv_main.c
@@ -1543,7 +1543,7 @@ int Rcon_Validate (char *client_string, char *password1)
                const char* digest = Cmd_Argv(1);
                const char* time_start = Cmd_Argv(1) + DIGEST_SIZE * 2;

-               if (strlen(digest) < DIGEST_SIZE * 2 + sizeof(time_t) * 2) {
+               if (strlen(digest) < DIGEST_SIZE * 2 + TIME_T_SIZE * 2) {
                        return 0;
                }

@@ -1552,9 +1552,9 @@ int Rcon_Validate (char *client_string, char *password1)
                        double difftime_server_client;

                        time(&server_time);
-                       for (i = 0; i < sizeof(client_time) * 2; i += 2) {
-                               client_time += (char2int((unsigned char)time_start[i]) << (4 + i * 4)) +
-                                              (char2int((unsigned char)time_start[i + 1]) << (i * 4));
+                       for (i = 0; i < TIME_T_SIZE * 2; i += 2) {
+                               client_time += ((time_t)char2int((unsigned char)time_start[i]) << (4 + i * 4)) +
+                                              ((time_t)char2int((unsigned char)time_start[i + 1]) << (i * 4));
                        }
                        difftime_server_client = difftime(server_time, client_time);

More information are here: https://github.com/QW-Group/ezquake-source/pull/719 https://github.com/QW-Group/ezquake-source/issues/726