From 6d6c294ae3b4a29dfcb9f8936d35fd84d2dec26d Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Thu, 15 Sep 2011 14:40:21 +0200 Subject: [PATCH] BUGFIX Consistently using Convert::raw2sql() instead of DB::getConn()->addslashes() or PHP's deprecated addslashes() for database escaping --- core/model/ComponentSet.php | 2 +- core/model/MySQLDatabase.php | 2 +- core/model/Versioned.php | 2 +- core/model/fieldtypes/Boolean.php | 2 +- core/model/fieldtypes/DBField.php | 2 +- core/model/fieldtypes/Decimal.php | 2 +- core/model/fieldtypes/Float.php | 2 +- core/model/fieldtypes/Int.php | 2 +- filesystem/File.php | 2 +- filesystem/Folder.php | 4 ++-- search/AdvancedSearchForm.php | 2 +- search/SearchForm.php | 2 +- 12 files changed, 13 insertions(+), 13 deletions(-) diff --git a/core/model/ComponentSet.php b/core/model/ComponentSet.php index 0c84b2775..06dba23d0 100755 --- a/core/model/ComponentSet.php +++ b/core/model/ComponentSet.php @@ -129,7 +129,7 @@ class ComponentSet extends DataObjectSet { $extraSQL = ''; if($extraFields) foreach($extraFields as $k => $v) { - $extraSQL .= ", $k = '" . addslashes($v) . "'"; + $extraSQL .= ", $k = '" . Convert::raw2sql($v) . "'"; } DB::query("INSERT INTO `$this->tableName` SET $parentField = {$this->ownerObj->ID}, $childField = {$item->ID} $extraSQL"); diff --git a/core/model/MySQLDatabase.php b/core/model/MySQLDatabase.php index e0815634e..52ef2e54e 100644 --- a/core/model/MySQLDatabase.php +++ b/core/model/MySQLDatabase.php @@ -290,7 +290,7 @@ class MySQLDatabase extends Database { } if($field['Default'] || $field['Default'] === "0") { - $fieldSpec .= " default '" . addslashes($field['Default']) . "'"; + $fieldSpec .= " default '" . Convert::raw2sql($field['Default']) . "'"; } if($field['Extra']) $fieldSpec .= " $field[Extra]"; diff --git a/core/model/Versioned.php b/core/model/Versioned.php index 5cc424159..64f0eaf84 100755 --- a/core/model/Versioned.php +++ b/core/model/Versioned.php @@ -273,7 +273,7 @@ class Versioned extends DataObjectDecorator { // Add any extra, unchanged fields to the version record. $data = DB::query("SELECT * FROM `$table` WHERE ID = $id")->record(); if($data) foreach($data as $k => $v) { - if (!isset($newManipulation['fields'][$k])) $newManipulation['fields'][$k] = "'" . addslashes($v) . "'"; + if (!isset($newManipulation['fields'][$k])) $newManipulation['fields'][$k] = "'" . Convert::raw2sql($v) . "'"; } // Set up a new entry in (table)_versions diff --git a/core/model/fieldtypes/Boolean.php b/core/model/fieldtypes/Boolean.php index 23516fb91..41d47ed83 100644 --- a/core/model/fieldtypes/Boolean.php +++ b/core/model/fieldtypes/Boolean.php @@ -64,7 +64,7 @@ class Boolean extends DBField { } if(!$value || !is_numeric($value)) { return "0"; } else { - return addslashes($value); + return Convert::raw2sql($value); } } diff --git a/core/model/fieldtypes/DBField.php b/core/model/fieldtypes/DBField.php index e5b4d2fdd..7b39e922f 100644 --- a/core/model/fieldtypes/DBField.php +++ b/core/model/fieldtypes/DBField.php @@ -106,7 +106,7 @@ abstract class DBField extends ViewableData { if($value === null || $value === "" || $value === false) { return "null"; } else { - return "'" . addslashes($value) . "'"; + return "'" . Convert::raw2sql($value) . "'"; } } diff --git a/core/model/fieldtypes/Decimal.php b/core/model/fieldtypes/Decimal.php index a4226e82b..a0f5ba107 100644 --- a/core/model/fieldtypes/Decimal.php +++ b/core/model/fieldtypes/Decimal.php @@ -55,7 +55,7 @@ class Decimal extends DBField { } if(!$value || !is_numeric($value)) { return "0"; } else { - return addslashes($value); + return Convert::raw2sql($value); } } diff --git a/core/model/fieldtypes/Float.php b/core/model/fieldtypes/Float.php index 489ca4e6d..59f708288 100644 --- a/core/model/fieldtypes/Float.php +++ b/core/model/fieldtypes/Float.php @@ -36,7 +36,7 @@ class Float extends DBField { } if(!$value || !is_numeric($value)) { return "0"; } else { - return addslashes($value); + return Convert::raw2sql($value); } } diff --git a/core/model/fieldtypes/Int.php b/core/model/fieldtypes/Int.php index 17623be53..c7b5121f5 100644 --- a/core/model/fieldtypes/Int.php +++ b/core/model/fieldtypes/Int.php @@ -52,7 +52,7 @@ class Int extends DBField { } if(!$value || !is_numeric($value)) { return "0"; } else { - return addslashes($value); + return Convert::raw2sql($value); } } diff --git a/filesystem/File.php b/filesystem/File.php index 4ff845aac..09ac7a981 100755 --- a/filesystem/File.php +++ b/filesystem/File.php @@ -332,7 +332,7 @@ class File extends DataObject { $ext = ""; } $suffix = 1; - while(DataObject::get_one("File", "Name = '" . addslashes($name) . "' AND ParentID = " . (int)$this->ParentID)) { + while(DataObject::get_one("File", "Name = '" . Convert::raw2sql($name) . "' AND ParentID = " . (int)$this->ParentID)) { $suffix++; $name = "$base-$suffix$ext"; } diff --git a/filesystem/Folder.php b/filesystem/Folder.php index 1b756bede..996e14560 100755 --- a/filesystem/Folder.php +++ b/filesystem/Folder.php @@ -159,10 +159,10 @@ class Folder extends File { if(Member::currentUser()) $ownerID = Member::currentUser()->ID; else $ownerID = 0; - $filename = addslashes($this->Filename . $name); + $filename = Convert::raw2sql($this->Filename . $name); if($className == 'Folder' ) $filename .= '/'; - $name = addslashes($name); + $name = Convert::raw2sql($name); DB::query("INSERT INTO `File` SET ClassName = '$className', ParentID = $this->ID, OwnerID = $ownerID, diff --git a/search/AdvancedSearchForm.php b/search/AdvancedSearchForm.php index 19c386709..2da17531b 100755 --- a/search/AdvancedSearchForm.php +++ b/search/AdvancedSearchForm.php @@ -82,7 +82,7 @@ class AdvancedSearchForm extends SearchForm { foreach($_REQUEST['OnlyShow'] as $section => $checked) { $items = explode(",", $section); foreach($items as $item) { - $page = DataObject::get_one('SiteTree', "URLSegment = '" . addslashes($item) . "'"); + $page = DataObject::get_one('SiteTree', "URLSegment = '" . Convert::raw2sql($item) . "'"); $pageList[] = $page->ID; if(!$page) user_error("Can't find a page called '$item'", E_USER_WARNING); $page->loadDescendantIDListInto($pageList); diff --git a/search/SearchForm.php b/search/SearchForm.php index e1719b04c..0b0778c1e 100755 --- a/search/SearchForm.php +++ b/search/SearchForm.php @@ -174,7 +174,7 @@ class SearchForm extends Form { public function searchEngine($keywords, $pageLength = null, $sortBy = "Relevance DESC", $extraFilter = "", $booleanSearch = false, $alternativeFileFilter = "", $invertedMatch = false) { if(!$pageLength) $pageLength = $this->pageLength; $fileFilter = ''; - $keywords = addslashes($keywords); + $keywords = Convert::raw2sql($keywords); $extraFilters = array('SiteTree' => '', 'File' => '');