2009-05-23 12 views
11

SQL注入:是sqlite3_bind_text足以防止由於語句iPhone

const char *sql = "INSERT INTO FooTable (barStr) VALUES (?)"; 

是以下使用的sqlite3_bind_text(及相關sqlite3_bind_*功能)足以防止SQL注入攻擊?

sqlite3 *db; 
sqlite3_stmt *dbps; 

int dbrc = sqlite3_open([dbFilePath UTF8String], &db); 
if (dbrc) { 
    // handle error 
    return; 
} 

dbrc = sqlite3_prepare_v2 (db, sql, -1, &dbps, NULL); 

sqlite3_bind_text(dbps, 1, [userContent UTF8String], -1, SQLITE_TRANSIENT); 

dbrc = sqlite3_step(dbps); 
if (SQLITE_DONE != dbrc) { 
    // handle error 
} 

sqlite3_finalize (dbps); 
sqlite3_close(db); 

回答

11

是的,如果你只通過用戶提供的數據,以sqlite3_bind_ *功能,那麼你是安全的SQL注入攻擊(這些攻擊假設你動態地構建您的查詢字符串,不報價/逃脫用戶正確提供的數據)。

+0

你能指點我一些文檔,證明`sqlite3_bind_text`函數是安全的SQL注入攻擊嗎?我沒有在文檔中發現綁定會過濾一些字符的提示嗎? (http://www.sqlite.org/c3ref/bind_blob.html) – 2017-06-09 15:08:18

相關問題