Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cbbdf736 authored by Michal Karpinski's avatar Michal Karpinski
Browse files

Improvements for SHA256_file_hash()

Bug: 26154009
Change-Id: I7cee0563edb7e8030716ae2925a940f3c158721e
parent 4db754fd
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -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);