Return when invalid config ID was provided through adb command and

change the separator of config_uid and config_id to underscore from dash
to disambiguate negative config ids

Bug: 73896814
Test: statsd_test
Change-Id: Ib0604e9f4c104560d570a64208a9e94d7526f8d6
This commit is contained in:
yro
2018-02-26 15:15:17 -08:00
parent 4e056c8bfa
commit 255f72e73e
2 changed files with 10 additions and 3 deletions

View File

@@ -423,6 +423,13 @@ status_t StatsService::cmd_config(FILE* in, FILE* out, FILE* err, Vector<String8
}
if (args[1] == "update") {
char* endp;
int64_t configID = strtoll(name.c_str(), &endp, 10);
if (endp == name.c_str() || *endp != '\0') {
fprintf(err, "Error parsing config ID.\n");
return UNKNOWN_ERROR;
}
// Read stream into buffer.
string buffer;
if (!android::base::ReadFdToString(fileno(in), &buffer)) {
@@ -438,7 +445,7 @@ status_t StatsService::cmd_config(FILE* in, FILE* out, FILE* err, Vector<String8
}
// Add / update the config.
mConfigManager->UpdateConfig(ConfigKey(uid, StrToInt64(name)), config);
mConfigManager->UpdateConfig(ConfigKey(uid, configID), config);
} else {
if (argCount == 2) {
cmd_remove_all_configs(out);

View File

@@ -367,7 +367,7 @@ void StatsdStats::dumpStats(FILE* out) const {
fprintf(out, "%lu Config in icebox: \n", (unsigned long)mIceBox.size());
for (const auto& configStats : mIceBox) {
fprintf(out,
"Config {%d-%lld}: creation=%d, deletion=%d, #metric=%d, #condition=%d, "
"Config {%d_%lld}: creation=%d, deletion=%d, #metric=%d, #condition=%d, "
"#matcher=%d, #alert=%d, valid=%d\n",
configStats.uid(), (long long)configStats.id(), configStats.creation_time_sec(),
configStats.deletion_time_sec(), configStats.metric_count(),
@@ -566,4 +566,4 @@ void StatsdStats::dumpStats(std::vector<uint8_t>* output, bool reset) {
} // namespace statsd
} // namespace os
} // namespace android
} // namespace android