summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Kralevich2015-04-07 12:46:23 -0500
committerGerrit Code Review2015-04-07 12:46:23 -0500
commit5fc47aae333520787d4373bc615a8ddcf58955ae (patch)
tree3baecc8da119c90754d6de6f6f4d63da5c7c39db
parent02f1d80ae2da2436c4c2e2a4643866871f41d54f (diff)
parent58ba58a97c8ec56b2c2a32d6cda19a3a57e3cccf (diff)
downloadplatform-system-core-5fc47aae333520787d4373bc615a8ddcf58955ae.tar.gz
platform-system-core-5fc47aae333520787d4373bc615a8ddcf58955ae.tar.xz
platform-system-core-5fc47aae333520787d4373bc615a8ddcf58955ae.zip
Merge "logd: Don't embed a flexible array member within another struct"
-rw-r--r--include/private/android_logger.h16
-rw-r--r--logd/LogAudit.cpp6
2 files changed, 17 insertions, 5 deletions
diff --git a/include/private/android_logger.h b/include/private/android_logger.h
index 724ca5173..04238a6fd 100644
--- a/include/private/android_logger.h
+++ b/include/private/android_logger.h
@@ -70,7 +70,17 @@ typedef struct __attribute__((__packed__)) {
70 android_event_long_t payload; 70 android_event_long_t payload;
71} android_log_event_long_t; 71} android_log_event_long_t;
72 72
73/* Event payload EVENT_TYPE_STRING */ 73/*
74 * Event payload EVENT_TYPE_STRING
75 *
76 * Danger: do not embed this structure into another structure.
77 * This structure uses a flexible array member, and when
78 * compiled using g++, __builtin_object_size(data, 1) returns
79 * a bad value. This is possibly a g++ bug, or a bug due to
80 * the fact that flexible array members are not supported
81 * in C++.
82 * http://stackoverflow.com/questions/4412749/are-flexible-array-members-valid-in-c
83 */
74typedef struct __attribute__((__packed__)) { 84typedef struct __attribute__((__packed__)) {
75 int8_t type; // EVENT_TYPE_STRING; 85 int8_t type; // EVENT_TYPE_STRING;
76 int32_t length; // Little Endian Order 86 int32_t length; // Little Endian Order
@@ -80,7 +90,9 @@ typedef struct __attribute__((__packed__)) {
80/* Event with single EVENT_TYPE_STRING */ 90/* Event with single EVENT_TYPE_STRING */
81typedef struct __attribute__((__packed__)) { 91typedef struct __attribute__((__packed__)) {
82 android_event_header_t header; 92 android_event_header_t header;
83 android_event_string_t payload; 93 int8_t type; // EVENT_TYPE_STRING;
94 int32_t length; // Little Endian Order
95 char data[];
84} android_log_event_string_t; 96} android_log_event_string_t;
85 97
86#endif 98#endif
diff --git a/logd/LogAudit.cpp b/logd/LogAudit.cpp
index 6b3e63718..bdb29158c 100644
--- a/logd/LogAudit.cpp
+++ b/logd/LogAudit.cpp
@@ -150,9 +150,9 @@ int LogAudit::logPrint(const char *fmt, ...) {
150 rc = -ENOMEM; 150 rc = -ENOMEM;
151 } else { 151 } else {
152 event->header.tag = htole32(AUDITD_LOG_TAG); 152 event->header.tag = htole32(AUDITD_LOG_TAG);
153 event->payload.type = EVENT_TYPE_STRING; 153 event->type = EVENT_TYPE_STRING;
154 event->payload.length = htole32(l); 154 event->length = htole32(l);
155 memcpy(event->payload.data, str, l); 155 memcpy(event->data, str, l);
156 156
157 logbuf->log(LOG_ID_EVENTS, now, uid, pid, tid, 157 logbuf->log(LOG_ID_EVENTS, now, uid, pid, tid,
158 reinterpret_cast<char *>(event), 158 reinterpret_cast<char *>(event),