Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: extensions/common/permissions/media_galleries_permission.cc

Issue 237693004: Fix NULL dereference if a extension subpermission is removed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add test Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/common/extensions/permissions/media_galleries_permission_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "extensions/common/permissions/media_galleries_permission.h" 5 #include "extensions/common/permissions/media_galleries_permission.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 MediaGalleriesPermission>(info) { 53 MediaGalleriesPermission>(info) {
54 } 54 }
55 55
56 MediaGalleriesPermission::~MediaGalleriesPermission() { 56 MediaGalleriesPermission::~MediaGalleriesPermission() {
57 } 57 }
58 58
59 bool MediaGalleriesPermission::FromValue( 59 bool MediaGalleriesPermission::FromValue(
60 const base::Value* value, 60 const base::Value* value,
61 std::string* error, 61 std::string* error,
62 std::vector<std::string>* unhandled_permissions) { 62 std::vector<std::string>* unhandled_permissions) {
63 std::vector<std::string> unhandled_sub_permissions; 63 size_t unhandled_permissions_count = 0;
64 if (!SetDisjunctionPermission<MediaGalleriesPermissionData, 64 if (unhandled_permissions)
65 MediaGalleriesPermission>::FromValue( 65 unhandled_permissions_count = unhandled_permissions->size();
66 value, error, &unhandled_sub_permissions)) { 66 bool parsed_ok =
67 unhandled_permissions->insert(unhandled_permissions->end(), 67 SetDisjunctionPermission<MediaGalleriesPermissionData,
68 unhandled_sub_permissions.begin(), 68 MediaGalleriesPermission>::FromValue(
69 unhandled_sub_permissions.end()); 69 value, error, unhandled_permissions);
70 if (unhandled_permissions) {
71 for (size_t i = unhandled_permissions_count;
72 i < unhandled_permissions->size();
73 i++) {
74 (*unhandled_permissions)[i] =
75 "{\"mediaGalleries\": [" + (*unhandled_permissions)[i] + "]}";
76 }
77 }
78 if (!parsed_ok)
70 return false; 79 return false;
71 }
72
73 for (size_t i = 0; i < unhandled_sub_permissions.size(); i++) {
74 unhandled_permissions->push_back(
75 "{\"mediaGalleries\": [" + unhandled_sub_permissions[i] + "]}");
76 }
77 80
78 bool has_read = false; 81 bool has_read = false;
79 bool has_copy_to = false; 82 bool has_copy_to = false;
80 bool has_delete = false; 83 bool has_delete = false;
81 for (std::set<MediaGalleriesPermissionData>::const_iterator it = 84 for (std::set<MediaGalleriesPermissionData>::const_iterator it =
82 data_set_.begin(); it != data_set_.end(); ++it) { 85 data_set_.begin(); it != data_set_.end(); ++it) {
83 if (it->permission() == kAllAutoDetectedPermission || 86 if (it->permission() == kAllAutoDetectedPermission ||
84 it->permission() == kScanPermission) { 87 it->permission() == kScanPermission) {
85 continue; 88 continue;
86 } 89 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 } 162 }
160 if (has_delete) { 163 if (has_delete) {
161 result.push_back(PermissionMessage( 164 result.push_back(PermissionMessage(
162 PermissionMessage::kMediaGalleriesAllGalleriesDelete, 165 PermissionMessage::kMediaGalleriesAllGalleriesDelete,
163 base::string16())); 166 base::string16()));
164 } 167 }
165 return result; 168 return result;
166 } 169 }
167 170
168 } // namespace extensions 171 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/common/extensions/permissions/media_galleries_permission_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698