Raised This Month: $12 Target: $400
 3% 

Secure SQL Query


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
AbeXito
Junior Member
Join Date: Sep 2008
Old 09-02-2008 , 13:14   Secure SQL Query
Reply With Quote #1

Hi There.

I'm writing my own real-time statistics for CS. I need to insert player name in database, so I'm doing this:
PHP Code:
format(sql_query,511,"SELECT * FROM `stats` WHERE `nick`='%s';"name)    
    new 
Handle:Query SQL_PrepareQuery(SqlConnection,sql_query)    
    if(!
SQL_Execute(Query))    {
        
SQL_QueryError(Query,g_Error,511)
        
server_print("* SQL Error: %s",g_Error)    
    }    
    if (
SQL_NumResults(Query) == 0) {    
        
format(sql_query,511,"INSERT `stats` (`nick`) VALUES ('%s');",name)        
        new 
Handle:Query2 SQL_PrepareQuery(SqlConnection,sql_query)    
        if(!
SQL_Execute(Query2))    {
            
SQL_QueryError(Query2,g_Error,511)
            
server_print("* SQL Error: %s",g_Error)
        }
        
SQL_FreeHandle(Query2)
    }
    
SQL_FreeHandle(Query
But if in player nick there are some special chars like " or ' or ` - query will fail and server can be hacked.

Replacing these chars to "_" or something is not good idea, because I need to store in DB real nickname. Also I can replace these symbols to {qout} {dblqout} {otherquot} and restore them.

Is there another way to insert in database " ' ` ?

My idea:
PHP Code:
replace(nick32"'""\'")
replace(nick32"`""\`")
replace(nick32"^"", "[slash here]^""
Will it works fine? Any suggestions?
AbeXito is offline
Send a message via Skype™ to AbeXito
danielkza
AMX Mod X Plugin Approver
Join Date: May 2007
Location: São Paulo - Brasil
Old 09-02-2008 , 13:42   Re: Secure SQL Query
Reply With Quote #2

http://www.amxmodx.org/funcwiki.php?go=func&id=1182
danielkza is offline
AbeXito
Junior Member
Join Date: Sep 2008
Old 09-02-2008 , 13:49   Re: Secure SQL Query
Reply With Quote #3

Thanks, danielkza
AbeXito is offline
Send a message via Skype™ to AbeXito
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 19:22.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode