sql_query 함수에 sql resource 지정 - 명랑폐인님 제안
This commit is contained in:
10
common.php
10
common.php
@ -64,9 +64,13 @@ if (file_exists($dbconfig_file)) {
|
||||
|
||||
$connect_db = sql_connect(G5_MYSQL_HOST, G5_MYSQL_USER, G5_MYSQL_PASSWORD) or die('MySQL Connect Error!!!');
|
||||
$select_db = sql_select_db(G5_MYSQL_DB, $connect_db) or die('MySQL DB Error!!!');
|
||||
@mysql_query(" set names utf8 ");
|
||||
if(defined('G5_MYSQL_SET_MODE') && G5_MYSQL_SET_MODE) @mysql_query("SET SESSION sql_mode = ''");
|
||||
if (defined(G5_TIMEZONE)) @mysql_query(" set time_zone = '".G5_TIMEZONE."'");
|
||||
|
||||
// mysql connect resource $g5 배열에 저장 - 명랑폐인님 제안
|
||||
$g5['connect_db'] = $connect_db;
|
||||
|
||||
sql_query(" set names utf8 ");
|
||||
if(defined('G5_MYSQL_SET_MODE') && G5_MYSQL_SET_MODE) sql_query("SET SESSION sql_mode = ''");
|
||||
if (defined(G5_TIMEZONE)) sql_query(" set time_zone = '".G5_TIMEZONE."'");
|
||||
|
||||
//==============================================================================
|
||||
// SQL Injection 등으로 부터 보호를 위해 sql_escape_string() 적용
|
||||
|
||||
@ -160,7 +160,7 @@ define('G5_DISPLAY_SQL_ERROR', TRUE);
|
||||
|
||||
// escape string 처리 함수 지정
|
||||
// POST 등에서 한글이 깨질 경우 addslashes 로 변경
|
||||
define('G5_ESCAPE_FUNCTION', 'mysql_real_escape_string');
|
||||
define('G5_ESCAPE_FUNCTION', 'sql_real_escape_string');
|
||||
|
||||
// 게시판에서 링크의 기본개수를 말합니다.
|
||||
// 필드를 추가하면 이 숫자를 필드수에 맞게 늘려주십시오.
|
||||
|
||||
@ -1464,18 +1464,23 @@ function sql_select_db($db, $connect)
|
||||
|
||||
|
||||
// mysql_query 와 mysql_error 를 한꺼번에 처리
|
||||
// mysql connect resource 지정 - 명랑폐인님 제안
|
||||
function sql_query($sql, $error=G5_DISPLAY_SQL_ERROR)
|
||||
{
|
||||
global $g5;
|
||||
|
||||
// Blind SQL Injection 취약점 해결
|
||||
$sql = trim($sql);
|
||||
// union의 사용을 허락하지 않습니다.
|
||||
$sql = preg_replace("#^select.*from.*union.*#i", "select 1", $sql);
|
||||
// `information_schema` DB로의 접근을 허락하지 않습니다.
|
||||
$sql = preg_replace("#^select.*from.*where.*`?information_schema`?.*#i", "select 1", $sql);
|
||||
|
||||
if ($error)
|
||||
$result = @mysql_query($sql) or die("<p>$sql<p>" . mysql_errno() . " : " . mysql_error() . "<p>error file : $_SERVER[PHP_SELF]");
|
||||
$result = @mysql_query($sql, $g5['connect_db']) or die("<p>$sql<p>" . mysql_errno() . " : " . mysql_error() . "<p>error file : {$_SERVER['PHP_SELF']}");
|
||||
else
|
||||
$result = @mysql_query($sql);
|
||||
$result = @mysql_query($sql, $g5['connect_db']);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
@ -1512,6 +1517,7 @@ function sql_password($value)
|
||||
// mysql 4.0x 이하 버전에서는 password() 함수의 결과가 16bytes
|
||||
// mysql 4.1x 이상 버전에서는 password() 함수의 결과가 41bytes
|
||||
$row = sql_fetch(" select password('$value') as pass ");
|
||||
|
||||
return $row['pass'];
|
||||
}
|
||||
|
||||
@ -1917,6 +1923,14 @@ function convert_charset($from_charset, $to_charset, $str)
|
||||
|
||||
|
||||
// mysql_real_escape_string 의 alias 기능을 한다.
|
||||
function sql_real_escape_string($field)
|
||||
{
|
||||
global $g5;
|
||||
|
||||
if($field)
|
||||
return mysql_real_escape_string($field, $g5['connect_db']);
|
||||
}
|
||||
|
||||
function escape_trim($field)
|
||||
{
|
||||
if ($field) {
|
||||
|
||||
Reference in New Issue
Block a user