summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Michal Karpinski <mkarpinski@google.com> 2016-01-07 20:45:02 +0000
committer Michal Karpinski <mkarpinski@google.com> 2016-01-07 20:45:02 +0000
commitcbbdf73608bace91270622034e4813a2355b7bf1 (patch)
tree265868088f212ba85882fc129f90a165e87a9ae8
parent4db754fd7c13993d81d98157f10e8015422d1e3a (diff)
Improvements for SHA256_file_hash()
Bug: 26154009 Change-Id: I7cee0563edb7e8030716ae2925a940f3c158721e
-rw-r--r--cmds/dumpstate/dumpstate.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp
index 9d017f0dfd..258a99f1dc 100644
--- a/cmds/dumpstate/dumpstate.cpp
+++ b/cmds/dumpstate/dumpstate.cpp
@@ -765,7 +765,8 @@ static bool finish_zip_file(const std::string& bugreport_name, const std::string
}
static std::string SHA256_file_hash(std::string filepath) {
- ScopedFd fd(TEMP_FAILURE_RETRY(open(filepath.c_str(), O_RDONLY | O_NONBLOCK | O_CLOEXEC)));
+ ScopedFd fd(TEMP_FAILURE_RETRY(open(filepath.c_str(), O_RDONLY | O_NONBLOCK | O_CLOEXEC
+ | O_NOFOLLOW)));
if (fd.get() == -1) {
ALOGE("open(%s): %s\n", filepath.c_str(), strerror(errno));
return NULL;
@@ -790,8 +791,8 @@ static std::string SHA256_file_hash(std::string filepath) {
uint8_t hash[SHA256_DIGEST_SIZE];
memcpy(hash, SHA256_final(&ctx), SHA256_DIGEST_SIZE);
char hash_buffer[SHA256_DIGEST_SIZE * 2 + 1];
- for(int i = 0; i < SHA256_DIGEST_SIZE; i++) {
- snprintf(hash_buffer + (i * 2), sizeof(hash_buffer), "%02x", hash[i]);
+ for(size_t i = 0; i < SHA256_DIGEST_SIZE; i++) {
+ sprintf(hash_buffer + (i * 2), "%02x", hash[i]);
}
hash_buffer[sizeof(hash_buffer) - 1] = 0;
return std::string(hash_buffer);