24.12.2014, 12:21
I've read that this warning refers to the string being too large, or too short, but I am not sure what the issue is in this case. Basically, I have a login system where it checks the user against the DB for his MD5 password. However, as soon as I type in the password into DIALOG_LOGIN, the server closes the connection.
mysql debug:
Console points towards sscanf buffer overflow the moment I'm kicked:
This is the code for the DIALOG_LOGIN:
And some defines for the code above:
"Password" field in DB is set as char(32).
mysql debug:
Код:
[03:15:33] >> mysql_real_escape_string( Connection handle: 1 ) [03:15:33] CMySQLHandler::EscapeString([SATC]HighFlyer); - Escaped 15 characters to [SATC]HighFlyer. [03:15:33] >> mysql_query( Connection handle: 1 ) [03:15:33] CMySQLHandler::Query(SELECT * FROM `Accounts` WHERE `Username` = '[SATC]HighFlyer' AND `Password` = md5('testing')) - Successfully executed. [03:15:33] >> mysql_store_result( Connection handle: 1 ) [03:15:33] CMySQLHandler::StoreResult() - Result was stored. [03:15:33] >> mysql_num_rows( Connection handle: 1 ) [03:15:33] CMySQLHandler::NumRows() - Returned 1 row(s) [03:15:33] >> mysql_fetch_row_format( Connection handle: 1 ) [03:15:33] CMySQLHandler::FetchRow() - Return: [SATC]HighFlyer|ae2b1fca515949e5d54fb22b8ed95575|127.0.0.1|23/5/1977|Vice City|312423|214748|14|5|0|0|0|3||236|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|||0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0 [03:15:33] --------------------------- [03:15:33] MySQL Debugging de-activated [03:15:33] ---------------------------
Код:
[03:15:30] Incoming connection: 127.0.0.1:50277 [03:15:30] [join] [SATC]HighFlyer has joined the server (0:127.0.0.1) [03:15:33] sscanf warning: String buffer overflow. [03:15:33] [part] [SATC]HighFlyer has left the server (0:2)
Код:
case DIALOG_LOGIN: { if(!response) // Cancel { Kick(playerid); return 1; } if(!inputtext[0]) { SendClientMessage(playerid, RED, "Error: Please enter a password."); Dialog_Login(playerid); return 1; } new esc_password[MAX_PASSWORD_LEN], query[512]; format(esc_password, sizeof(esc_password), "%s", inputtext); mysql_debug(1); format(query, sizeof(query), "SELECT * FROM `Accounts` WHERE `Username` = '%s' AND `Password` = md5('%s')", GetPlayerEscapedName(playerid), esc_password); mysql_query(query); mysql_store_result(); if(mysql_num_rows() != 0) // Password is correct { new result[1024]; mysql_fetch_row_format(result); if(sscanf(result, MYSQL_PLAYER_LOAD_FORMAT, Player[playerid])) { WipeChat(playerid); SendClientMessage(playerid, WHITE, "There was an error with the format of your account data."); SendClientMessage(playerid, WHITE, "Please take a screenshot, if you know how, and post it as a bug report."); SendClientMessage(playerid, WHITE, "Forums: "FORUMS""); Kick(playerid); mysql_debug(0); return 1; } OnPlayerLogin(playerid); } else { Player[playerid][LoginAttempts]++; format(str, sizeof(str), "Error: Invalid password (%d/%d)", Player[playerid][LoginAttempts], MAX_LOGIN_ATTEMPTS); SendClientMessage(playerid, RED, str); if(Player[playerid][LoginAttempts] >= MAX_LOGIN_ATTEMPTS) // He has tried to login MAX_LOGIN_ATTEMPTS times (or more if that was to somehow happen..) { SendClientMessage(playerid, RED, "Error: Too many login attempts, you have been kicked."); Player[playerid][LoginAttempts] = 0; Kick(playerid); return 1; } Dialog_Login(playerid); } mysql_free_result(); }
Код:
#define MAX_PASSWORD_LEN (32) #define MYSQL_PLAYER_LOAD_FORMAT "e<p<|>s[24]s[32]s[16]s[16]s[24]dddddddds[12]dddddddddddddddds[128]s[24]dds[24]ddddddddddddddddddddddddddddddddddddddddddddddddddddddffddddddddd>"