Extensions: BaseSetOperators<T> copy/assignment code is not being called |
||
Issue description
BaseSetOperators<T> is the parent class for both APIPermissionSet and ManifestPermissionSet, and provides set-like functionality. It has deliberate copy constructor [1] and assignment operator [2] methods, which are designed to allow safely copying the permission sets. However, in practice, these methods are not used.
These are declared in the file as
explicit BaseSetOperators(const T& set) { this->operator=(set); }
~BaseSetOperators() {}
T& operator=(const T& rhs) {
return Assign(rhs);
}
An example call site would be trying to copy an APIPermissionSet, which inherits BaseSetOperators<APIPermissionSet>(). However, the way the compiler looks for a suitable constructor is:
(A) Look for APIPermissionSet::APIPermissionSet(const APIPermissionSet&) (and variants)
(B) Look for BaseSetOperators<APIPermissionSet>::BaseSetOperators<APIPermissionSet>(const BaseSetOperators<APIPermissionSet>& other) (and variants)
The BaseSetOperator code effectively declares `BaseSetOperators<APIPermissionSet>::BaseSetOperators<APIPermissionSet>(const APIPermissionSet& other)`.
Since BaseSetOperators are designed to be copyable and assignable, we don't use DISALLOW_COPY_AND_ASSIGN(). The only member in BaseSetOperators in the map, which is of type `std::map<ElementIDType, linked_ptr<ElementType>>`, which is copyable/assignable. This results in the compiler "helpfully" generating the missing constructor functions from (A). This means that all the bespoke copying code we had in [1], [2], and [3] are completely ignored, and the map is directly copied.
What's more, it looks like at least two tests are exercising this (improper) behavior.
,
Nov 29
The following revision refers to this bug: https://chromium.googlesource.com/chromium/src.git/+/2251840ff932d4a5dcd1ce62f84e01ca14d246b7 commit 2251840ff932d4a5dcd1ce62f84e01ca14d246b7 Author: Devlin Cronin <rdevlin.cronin@chromium.org> Date: Thu Nov 29 01:35:03 2018 [Extensions] Fix BaseSetOperators<> copy/assignment methods There were two issues with the BaseSetOperators copy constructor and assignment operator: 1) The methods were declared to take a const T&, rather than a const BaseSetOperators<T>&. This meant that, since BaseSetOperators didn't delete the default copy/assignment methods, the result was that code would use the compiler-generated versions, bypassing our safer copy methods. 2) Once fixing that so that the custom copy/assignment methods are called, the assignment operator did not clear the map. This meant that any previous values in the map would remain present. Fix both of these issues, and add regression unittests. Bug: 908619 Change-Id: Id633467f165801f2be09f453f5c46102f023b687 Reviewed-on: https://chromium-review.googlesource.com/c/1351886 Commit-Queue: Devlin <rdevlin.cronin@chromium.org> Reviewed-by: Istiaque Ahmed <lazyboy@chromium.org> Cr-Commit-Position: refs/heads/master@{#611980} [modify] https://crrev.com/2251840ff932d4a5dcd1ce62f84e01ca14d246b7/extensions/common/BUILD.gn [modify] https://crrev.com/2251840ff932d4a5dcd1ce62f84e01ca14d246b7/extensions/common/permissions/base_set_operators.h [add] https://crrev.com/2251840ff932d4a5dcd1ce62f84e01ca14d246b7/extensions/common/permissions/base_set_operators_unittest.cc
,
Nov 29
|
||
►
Sign in to add a comment |
||
Comment 1 by rdevlin....@chromium.org
, Nov 26