| OLD | NEW |
| 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 "components/metrics/serialization/serialization_utils.h" | 5 #include "components/metrics/serialization/serialization_utils.h" |
| 6 | 6 |
| 7 #include <sys/file.h> | 7 #include <sys/file.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 return false; | 49 return false; |
| 50 } | 50 } |
| 51 if (result < static_cast<int>(sizeof(message_size))) { | 51 if (result < static_cast<int>(sizeof(message_size))) { |
| 52 DLOG(ERROR) << "bad read size " << result << ", expecting " | 52 DLOG(ERROR) << "bad read size " << result << ", expecting " |
| 53 << sizeof(message_size); | 53 << sizeof(message_size); |
| 54 return false; | 54 return false; |
| 55 } | 55 } |
| 56 | 56 |
| 57 // kMessageMaxLength applies to the entire message: the 4-byte | 57 // kMessageMaxLength applies to the entire message: the 4-byte |
| 58 // length field and the content. | 58 // length field and the content. |
| 59 if (message_size > metrics::SerializationUtils::kMessageMaxLength) { | 59 if (message_size > SerializationUtils::kMessageMaxLength) { |
| 60 DLOG(ERROR) << "message too long : " << message_size; | 60 DLOG(ERROR) << "message too long : " << message_size; |
| 61 if (HANDLE_EINTR(lseek(fd, message_size - 4, SEEK_CUR)) == -1) { | 61 if (HANDLE_EINTR(lseek(fd, message_size - 4, SEEK_CUR)) == -1) { |
| 62 DLOG(ERROR) << "error while skipping message. abort"; | 62 DLOG(ERROR) << "error while skipping message. abort"; |
| 63 return false; | 63 return false; |
| 64 } | 64 } |
| 65 // Badly formatted message was skipped. Treat the badly formatted sample as | 65 // Badly formatted message was skipped. Treat the badly formatted sample as |
| 66 // an empty sample. | 66 // an empty sample. |
| 67 message->clear(); | 67 message->clear(); |
| 68 return true; | 68 return true; |
| 69 } | 69 } |
| 70 | 70 |
| 71 message_size -= sizeof(message_size); // The message size includes itself. | 71 message_size -= sizeof(message_size); // The message size includes itself. |
| 72 char buffer[metrics::SerializationUtils::kMessageMaxLength]; | 72 char buffer[SerializationUtils::kMessageMaxLength]; |
| 73 if (!base::ReadFromFD(fd, buffer, message_size)) { | 73 if (!base::ReadFromFD(fd, buffer, message_size)) { |
| 74 DPLOG(ERROR) << "reading metrics message body"; | 74 DPLOG(ERROR) << "reading metrics message body"; |
| 75 return false; | 75 return false; |
| 76 } | 76 } |
| 77 *message = std::string(buffer, message_size); | 77 *message = std::string(buffer, message_size); |
| 78 return true; | 78 return true; |
| 79 } | 79 } |
| 80 | 80 |
| 81 } // namespace | 81 } // namespace |
| 82 | 82 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 if (!base::WriteFileDescriptor( | 206 if (!base::WriteFileDescriptor( |
| 207 file_descriptor.get(), msg.c_str(), msg.size())) { | 207 file_descriptor.get(), msg.c_str(), msg.size())) { |
| 208 DPLOG(ERROR) << "error writing message"; | 208 DPLOG(ERROR) << "error writing message"; |
| 209 return false; | 209 return false; |
| 210 } | 210 } |
| 211 | 211 |
| 212 return true; | 212 return true; |
| 213 } | 213 } |
| 214 | 214 |
| 215 } // namespace metrics | 215 } // namespace metrics |
| OLD | NEW |