Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where a % in a serialized array can lead to the data being broken #16694

Merged
merged 1 commit into from
Mar 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CRM/Dedupe/Finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,12 @@ public static function parseAndStoreDupePairs($foundDupes, $cacheKeyString) {
'canMerge' => TRUE,
];

$data = CRM_Core_DAO::escapeString(serialize($row));
CRM_Core_DAO::executeQuery("INSERT INTO civicrm_prevnext_cache (entity_table, entity_id1, entity_id2, cacheKey, data) VALUES
('civicrm_contact', %1, %2, %3, '{$data}')", [
('civicrm_contact', %1, %2, %3, %4)", [
1 => [$dstID, 'Integer'],
2 => [$srcID, 'Integer'],
3 => [$cacheKeyString, 'String'],
4 => [serialize($row), 'String'],
]
);
}
Expand Down
3 changes: 1 addition & 2 deletions CRM/Dedupe/Merger.php
Original file line number Diff line number Diff line change
Expand Up @@ -775,10 +775,9 @@ public static function updateMergeStats($cacheKeyString, $result = []) {
'merged' => (int) $merged,
'skipped' => (int) $skipped,
];
$data = serialize($data);

CRM_Core_DAO::executeQuery("INSERT INTO civicrm_prevnext_cache (entity_table, entity_id1, entity_id2, cacheKey, data) VALUES
('civicrm_contact', 0, 0, %1, '{$data}')", [1 => [$cacheKeyString . '_stats', 'String']]);
('civicrm_contact', 0, 0, %1, %2)", [1 => [$cacheKeyString . '_stats', 'String'], 2 => [serialize($data), 'String']]);
}

/**
Expand Down
16 changes: 16 additions & 0 deletions tests/phpunit/api/v3/JobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,22 @@ public function getMergeLocationData() {

}

/**
* Test weird characters don't mess with merge & cause a fatal.
*
* @throws \CRM_Core_Exception
*/
public function testNoErrorOnOdd() {
$this->individualCreate();
$this->individualCreate(['first_name' => 'Gerrit%0a%2e%0a']);
$this->callAPISuccess('Job', 'process_batch_merge', []);

$this->individualCreate();
$this->individualCreate(['first_name' => '[foo\\bar\'baz']);
$this->callAPISuccess('Job', 'process_batch_merge', []);
$this->callAPISuccessGetSingle('Contact', ['first_name' => '[foo\\bar\'baz']);
}

/**
* Test the batch merge does not create duplicate emails.
*
Expand Down