Merge "Address property service DoS."
diff --git a/liblog/logprint.c b/liblog/logprint.c
index e61850d..af52528 100644
--- a/liblog/logprint.c
+++ b/liblog/logprint.c
@@ -625,14 +625,14 @@
}
static bool findChar(const char** cp, size_t* len, int c) {
- while (*len && isspace(**cp)) {
- ++*cp;
- --*len;
+ while ((*len) && isspace(*(*cp))) {
+ ++(*cp);
+ --(*len);
}
if (c == INT_MAX) return *len;
- if (*len && (**cp == c)) {
- ++*cp;
- --*len;
+ if ((*len) && (*(*cp) == c)) {
+ ++(*cp);
+ --(*len);
return true;
}
return false;
@@ -991,7 +991,7 @@
LIBLOG_ABI_PUBLIC int android_log_processBinaryLogBuffer(
struct logger_entry *buf,
AndroidLogEntry *entry,
- const EventTagMap *map __unused,
+ const EventTagMap *map __unused, // only on !__ANDROID__
char *messageBuf, int messageBufLen)
{
size_t inCount;
diff --git a/logd/CommandListener.cpp b/logd/CommandListener.cpp
index 74e0ea5..6ad7351 100644
--- a/logd/CommandListener.cpp
+++ b/logd/CommandListener.cpp
@@ -301,6 +301,7 @@
const char *name = NULL;
const char *format = NULL;
+ const char *id = NULL;
for (int i = 1; i < argc; ++i) {
static const char _name[] = "name=";
if (!strncmp(argv[i], _name, strlen(_name))) {
@@ -313,6 +314,21 @@
format = argv[i] + strlen(_format);
continue;
}
+
+ static const char _id[] = "id=";
+ if (!strncmp(argv[i], _id, strlen(_id))) {
+ id = argv[i] + strlen(_id);
+ continue;
+ }
+ }
+
+ if (id) {
+ if (format || name) {
+ cli->sendMsg("can not mix id= with either format= or name=");
+ return 0;
+ }
+ cli->sendMsg(package_string(mBuf.formatEntry(atoi(id), uid)).c_str());
+ return 0;
}
cli->sendMsg(package_string(mBuf.formatGetEventTag(uid,
diff --git a/logd/LogBuffer.h b/logd/LogBuffer.h
index da63e12..9feef32 100644
--- a/logd/LogBuffer.h
+++ b/logd/LogBuffer.h
@@ -140,6 +140,9 @@
const char *name, const char *format) {
return tags.formatGetEventTag(uid, name, format);
}
+ std::string formatEntry(uint32_t tag, uid_t uid) {
+ return tags.formatEntry(tag, uid);
+ }
const char *tagToName(uint32_t tag) { return tags.tagToName(tag); }
// helper must be protected directly or implicitly by lock()/unlock()
diff --git a/logd/LogTags.cpp b/logd/LogTags.cpp
index a109592..64aa219 100644
--- a/logd/LogTags.cpp
+++ b/logd/LogTags.cpp
@@ -836,6 +836,11 @@
return ret;
}
+std::string LogTags::formatEntry(uint32_t tag, uid_t uid) {
+ android::RWLock::AutoRLock readLock(rwlock);
+ return formatEntry_locked(tag, uid);
+}
+
std::string LogTags::formatGetEventTag(uid_t uid,
const char* name, const char* format) {
bool all = name && (name[0] == '*') && !name[1];
diff --git a/logd/LogTags.h b/logd/LogTags.h
index 37a6d96..4457c46 100644
--- a/logd/LogTags.h
+++ b/logd/LogTags.h
@@ -106,6 +106,7 @@
// reverse lookup from tag
const char* tagToName(uint32_t tag) const;
const char* tagToFormat(uint32_t tag) const;
+ std::string formatEntry(uint32_t tag, uid_t uid);
// find associated tag
uint32_t nameToTag(const char* name) const;
diff --git a/logd/tests/logd_test.cpp b/logd/tests/logd_test.cpp
index adf583b..8a35059 100644
--- a/logd/tests/logd_test.cpp
+++ b/logd/tests/logd_test.cpp
@@ -836,6 +836,23 @@
#endif
}
+TEST(logd, getEventTag_42) {
+#ifdef __ANDROID__
+ char buffer[256];
+ memset(buffer, 0, sizeof(buffer));
+ snprintf(buffer, sizeof(buffer), "getEventTag id=42");
+ send_to_control(buffer, sizeof(buffer));
+ buffer[sizeof(buffer) - 1] = '\0';
+ char *cp;
+ long ret = strtol(buffer, &cp, 10);
+ EXPECT_GT(ret, 16);
+ EXPECT_TRUE(strstr(buffer, "\t(to life the universe etc|3)") != NULL);
+ EXPECT_TRUE(strstr(buffer, "answer") != NULL);
+#else
+ GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif
+}
+
TEST(logd, getEventTag_newentry) {
#ifdef __ANDROID__
char buffer[256];