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

Side by Side Diff: util/mac/xattr.cc

Issue 1283243004: ubsan: Don’t call v[0] on empty vectors (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 5 years, 4 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
« no previous file with comments | « snapshot/minidump/process_snapshot_minidump.cc ('k') | util/mach/child_port_handshake.cc » ('j') | 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 Crashpad Authors. All rights reserved. 1 // Copyright 2014 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 23 matching lines...) Expand all
34 0, 0, 0); 34 0, 0, 0);
35 if (buffer_size < 0) { 35 if (buffer_size < 0) {
36 if (errno == ENOATTR) 36 if (errno == ENOATTR)
37 return XattrStatus::kNoAttribute; 37 return XattrStatus::kNoAttribute;
38 PLOG(ERROR) << "getxattr size " << name << " on file " << file.value(); 38 PLOG(ERROR) << "getxattr size " << name << " on file " << file.value();
39 return XattrStatus::kOtherError; 39 return XattrStatus::kOtherError;
40 } 40 }
41 41
42 // Resize the buffer and read into it. 42 // Resize the buffer and read into it.
43 value->resize(buffer_size); 43 value->resize(buffer_size);
44 ssize_t bytes_read = getxattr(file.value().c_str(), name.data(), 44 if (!value->empty()) {
45 &(*value)[0], value->size(), 45 ssize_t bytes_read = getxattr(file.value().c_str(), name.data(),
46 0, 0); 46 &(*value)[0], value->size(),
47 if (bytes_read < 0) { 47 0, 0);
48 PLOG(ERROR) << "getxattr " << name << " on file " << file.value(); 48 if (bytes_read < 0) {
49 return XattrStatus::kOtherError; 49 PLOG(ERROR) << "getxattr " << name << " on file " << file.value();
50 return XattrStatus::kOtherError;
51 }
52 DCHECK_EQ(bytes_read, buffer_size);
50 } 53 }
51 DCHECK_EQ(bytes_read, buffer_size);
52 54
53 return XattrStatus::kOK; 55 return XattrStatus::kOK;
54 } 56 }
55 57
56 bool WriteXattr(const base::FilePath& file, 58 bool WriteXattr(const base::FilePath& file,
57 const base::StringPiece& name, 59 const base::StringPiece& name,
58 const std::string& value) { 60 const std::string& value) {
59 int rv = setxattr(file.value().c_str(), name.data(), value.c_str(), 61 int rv = setxattr(file.value().c_str(), name.data(), value.c_str(),
60 value.length(), 0, 0); 62 value.length(), 0, 0);
61 PLOG_IF(ERROR, rv != 0) << "setxattr " << name << " on file " 63 PLOG_IF(ERROR, rv != 0) << "setxattr " << name << " on file "
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 } 141 }
140 142
141 bool WriteXattrTimeT(const base::FilePath& file, 143 bool WriteXattrTimeT(const base::FilePath& file,
142 const base::StringPiece& name, 144 const base::StringPiece& name,
143 time_t value) { 145 time_t value) {
144 std::string tmp = base::StringPrintf("%ld", value); 146 std::string tmp = base::StringPrintf("%ld", value);
145 return WriteXattr(file, name, tmp); 147 return WriteXattr(file, name, tmp);
146 } 148 }
147 149
148 } // namespace crashpad 150 } // namespace crashpad
OLDNEW
« no previous file with comments | « snapshot/minidump/process_snapshot_minidump.cc ('k') | util/mach/child_port_handshake.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698