summaryrefslogtreecommitdiffstats
path: root/otafault/config.cpp
diff options
context:
space:
mode:
authorJed Estep <jestep@google.com>2016-03-22 23:25:27 +0100
committerJed Estep <jestep@google.com>2016-03-23 01:57:23 +0100
commit88dd7796a1fd4c64d57afb20021bf66cb26fa886 (patch)
tree24defdc9fb1133ae8d01f3c577b924d94e9130b9 /otafault/config.cpp
parentControl fault injection with config files instead of build flags (diff)
downloadandroid_bootable_recovery-88dd7796a1fd4c64d57afb20021bf66cb26fa886.tar
android_bootable_recovery-88dd7796a1fd4c64d57afb20021bf66cb26fa886.tar.gz
android_bootable_recovery-88dd7796a1fd4c64d57afb20021bf66cb26fa886.tar.bz2
android_bootable_recovery-88dd7796a1fd4c64d57afb20021bf66cb26fa886.tar.lz
android_bootable_recovery-88dd7796a1fd4c64d57afb20021bf66cb26fa886.tar.xz
android_bootable_recovery-88dd7796a1fd4c64d57afb20021bf66cb26fa886.tar.zst
android_bootable_recovery-88dd7796a1fd4c64d57afb20021bf66cb26fa886.zip
Diffstat (limited to '')
-rw-r--r--otafault/config.cpp31
1 files changed, 15 insertions, 16 deletions
diff --git a/otafault/config.cpp b/otafault/config.cpp
index aa4b4d5ce..b4567392d 100644
--- a/otafault/config.cpp
+++ b/otafault/config.cpp
@@ -20,6 +20,8 @@
#include <stdio.h>
#include <unistd.h>
+#include <android-base/stringprintf.h>
+
#include "minzip/Zip.h"
#include "config.h"
#include "ota_io.h"
@@ -27,12 +29,10 @@
#define OTAIO_MAX_FNAME_SIZE 128
static ZipArchive* archive;
-static std::map<const char*, bool> should_inject_cache;
+static std::map<std::string, bool> should_inject_cache;
-static const char* get_type_path(const char* io_type) {
- char* path = (char*)calloc(strlen(io_type) + strlen(OTAIO_BASE_DIR) + 2, sizeof(char));
- sprintf(path, "%s/%s", OTAIO_BASE_DIR, io_type);
- return path;
+static std::string get_type_path(const char* io_type) {
+ return android::base::StringPrintf("%s/%s", OTAIO_BASE_DIR, io_type);
}
void ota_io_init(ZipArchive* za) {
@@ -46,13 +46,12 @@ bool should_fault_inject(const char* io_type) {
if (archive == NULL) {
return false;
}
- if (should_inject_cache.find(io_type) != should_inject_cache.end()) {
- return should_inject_cache[io_type];
+ const std::string type_path = get_type_path(io_type);
+ if (should_inject_cache.find(type_path) != should_inject_cache.end()) {
+ return should_inject_cache[type_path];
}
- const char* type_path = get_type_path(io_type);
- const ZipEntry* entry = mzFindZipEntry(archive, type_path);
+ const ZipEntry* entry = mzFindZipEntry(archive, type_path.c_str());
should_inject_cache[type_path] = entry != nullptr;
- free((void*)type_path);
return entry != NULL;
}
@@ -61,10 +60,10 @@ bool should_hit_cache() {
}
std::string fault_fname(const char* io_type) {
- const char* type_path = get_type_path(io_type);
- char* fname = (char*) calloc(OTAIO_MAX_FNAME_SIZE, sizeof(char));
- const ZipEntry* entry = mzFindZipEntry(archive, type_path);
- mzReadZipEntry(archive, entry, fname, OTAIO_MAX_FNAME_SIZE);
- free((void*)type_path);
- return std::string(fname);
+ std::string type_path = get_type_path(io_type);
+ std::string fname;
+ fname.resize(OTAIO_MAX_FNAME_SIZE);
+ const ZipEntry* entry = mzFindZipEntry(archive, type_path.c_str());
+ mzReadZipEntry(archive, entry, &fname[0], OTAIO_MAX_FNAME_SIZE);
+ return fname;
}