Skip to content

Commit

Permalink
Merge pull request from GHSA-qv6w-68gq-wx2v
Browse files Browse the repository at this point in the history
CVE-2020-15108

Add test to reproduce error
Add test on calendar duplication
  • Loading branch information
trasher committed Jul 16, 2020
1 parent 78f7e40 commit a4baa64
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion inc/calendar.class.php
Expand Up @@ -201,7 +201,7 @@ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBT
*/
function duplicate($options = []) {

$input = $this->fields;
$input = Toolbox::addslashes_deep($this->fields);
unset($input['id']);

if (is_array($options) && count($options)) {
Expand Down
2 changes: 1 addition & 1 deletion inc/commondbtm.class.php
Expand Up @@ -1206,7 +1206,7 @@ function clone(array $override_input = [], bool $history = true) {
return false;
}
$new_item = new static();
$input = $this->fields;
$input = Toolbox::addslashes_deep($this->fields);
foreach ($override_input as $key => $value) {
$input[$key] = $value;
}
Expand Down
14 changes: 14 additions & 0 deletions tests/functionnal/Calendar.php
Expand Up @@ -254,5 +254,19 @@ public function testClone() {
$this->boolean($calendar->getFromDB($id))->isTrue();
//should have been duplicated too.
$this->checkXmas($calendar);

//change name, and clone again
$this->boolean($calendar->update(['id' => $id, 'name' => "Je s\'apelle Groot"]))->isTrue();

$calendar = new \Calendar();
$this->boolean($calendar->getFromDB($id))->isTrue();

$this->boolean($calendar->duplicate())->isTrue();
$other_id = $calendar->fields['id'];
$this->integer($other_id)->isGreaterThan($id);
$this->boolean($calendar->getFromDB($other_id))->isTrue();
//should have been duplicated too.
$this->checkXmas($calendar);

}
}
18 changes: 13 additions & 5 deletions tests/functionnal/Computer.php
Expand Up @@ -38,14 +38,20 @@

class Computer extends DbTestCase {

protected function getUniqueString() {
$string = parent::getUniqueString();
$string .= "with a ' inside!";
return $string;
}

private function getNewComputer() {
$computer = getItemByTypeName('Computer', '_test_pc01');
$fields = $computer->fields;
unset($fields['id']);
unset($fields['date_creation']);
unset($fields['date_mod']);
$fields['name'] = $this->getUniqueString();
$this->integer((int)$computer->add($fields))->isGreaterThan(0);
$this->integer((int)$computer->add(\Toolbox::addslashes_deep($fields)))->isGreaterThan(0);
return $computer;
}

Expand All @@ -56,7 +62,7 @@ private function getNewPrinter() {
unset($pfields['date_creation']);
unset($pfields['date_mod']);
$pfields['name'] = $this->getUniqueString();
$this->integer((int)$printer->add($pfields))->isGreaterThan(0);
$this->integer((int)$printer->add(\Toolbox::addslashes_deep($pfields)))->isGreaterThan(0);
return $printer;
}

Expand Down Expand Up @@ -89,7 +95,7 @@ public function testUpdate() {
'states_id' => $this->getUniqueInteger(),
'locations_id' => $this->getUniqueInteger(),
];
$this->boolean($computer->update($in))->isTrue();
$this->boolean($computer->update(\Toolbox::addslashes_deep($in)))->isTrue();
$this->boolean($computer->getFromDB($computer->getID()))->isTrue();
$this->boolean($printer->getFromDB($printer->getID()))->isTrue();
unset($in['id']);
Expand Down Expand Up @@ -134,7 +140,7 @@ public function testUpdate() {
'states_id' => $this->getUniqueInteger(),
'locations_id' => $this->getUniqueInteger(),
];
$this->boolean($computer->update($in2))->isTrue();
$this->boolean($computer->update(\Toolbox::addslashes_deep($in2)))->isTrue();
$this->boolean($computer->getFromDB($computer->getID()))->isTrue();
$this->boolean($printer->getFromDB($printer->getID()))->isTrue();
unset($in2['id']);
Expand Down Expand Up @@ -255,7 +261,7 @@ public function testCreateLinks() {
'states_id' => $this->getUniqueInteger(),
'locations_id' => $this->getUniqueInteger(),
];
$this->boolean($computer->update($in))->isTrue();
$this->boolean($computer->update(\Toolbox::addslashes_deep($in)))->isTrue();
$this->boolean($computer->getFromDB($computer->getID()))->isTrue();

$printer = new \Printer();
Expand Down Expand Up @@ -431,6 +437,8 @@ public function testClone() {
)->isGreaterThan(0);

//clone!
$computer = new \Computer(); //$computer->fields contents is already escaped!
$this->boolean($computer->getFromDB($id))->isTrue();
$added = $computer->clone();
$this->integer((int)$added)->isGreaterThan(0);
$this->integer($added)->isNotEqualTo($computer->fields['id']);
Expand Down

0 comments on commit a4baa64

Please sign in to comment.