Merge "Fix the android-cloexec-* warnings in bootable/recovery" am: 94a8ea1797 am: 6d8827e0d3
am: 96b5bb9601
Change-Id: I55911c112a34797d7c7098e5e325145667b46715
This commit is contained in:
+1
-1
@@ -265,7 +265,7 @@ int update_binary_command(const std::string& package, ZipArchiveHandle zip,
|
|||||||
}
|
}
|
||||||
|
|
||||||
unlink(binary_path.c_str());
|
unlink(binary_path.c_str());
|
||||||
int fd = creat(binary_path.c_str(), 0755);
|
int fd = open(binary_path.c_str(), O_CREAT | O_WRONLY | O_TRUNC | O_CLOEXEC, 0755);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
PLOG(ERROR) << "Failed to create " << binary_path;
|
PLOG(ERROR) << "Failed to create " << binary_path;
|
||||||
return INSTALL_ERROR;
|
return INSTALL_ERROR;
|
||||||
|
|||||||
+1
-1
@@ -56,7 +56,7 @@ static int open_png(const char* name, png_structp* png_ptr, png_infop* info_ptr,
|
|||||||
|
|
||||||
snprintf(resPath, sizeof(resPath)-1, "/res/images/%s.png", name);
|
snprintf(resPath, sizeof(resPath)-1, "/res/images/%s.png", name);
|
||||||
resPath[sizeof(resPath)-1] = '\0';
|
resPath[sizeof(resPath)-1] = '\0';
|
||||||
FILE* fp = fopen(resPath, "rb");
|
FILE* fp = fopen(resPath, "rbe");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
result = -1;
|
result = -1;
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|||||||
+15
-15
@@ -59,21 +59,21 @@ static void check_and_fclose(FILE *fp, const char *name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void copy_file(const char* source, const char* destination) {
|
static void copy_file(const char* source, const char* destination) {
|
||||||
FILE* dest_fp = fopen(destination, "w");
|
FILE* dest_fp = fopen(destination, "we");
|
||||||
if (dest_fp == nullptr) {
|
if (dest_fp == nullptr) {
|
||||||
PLOG(ERROR) << "Can't open " << destination;
|
PLOG(ERROR) << "Can't open " << destination;
|
||||||
} else {
|
} else {
|
||||||
FILE* source_fp = fopen(source, "r");
|
FILE* source_fp = fopen(source, "re");
|
||||||
if (source_fp != nullptr) {
|
if (source_fp != nullptr) {
|
||||||
char buf[4096];
|
char buf[4096];
|
||||||
size_t bytes;
|
size_t bytes;
|
||||||
while ((bytes = fread(buf, 1, sizeof(buf), source_fp)) != 0) {
|
while ((bytes = fread(buf, 1, sizeof(buf), source_fp)) != 0) {
|
||||||
fwrite(buf, 1, bytes, dest_fp);
|
fwrite(buf, 1, bytes, dest_fp);
|
||||||
}
|
}
|
||||||
check_and_fclose(source_fp, source);
|
check_and_fclose(source_fp, source);
|
||||||
}
|
|
||||||
check_and_fclose(dest_fp, destination);
|
|
||||||
}
|
}
|
||||||
|
check_and_fclose(dest_fp, destination);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool rotated = false;
|
static bool rotated = false;
|
||||||
@@ -120,7 +120,7 @@ int main(int argc, char **argv) {
|
|||||||
*/
|
*/
|
||||||
bool has_cache = false;
|
bool has_cache = false;
|
||||||
static const char mounts_file[] = "/proc/mounts";
|
static const char mounts_file[] = "/proc/mounts";
|
||||||
FILE *fp = fopen(mounts_file, "r");
|
FILE* fp = fopen(mounts_file, "re");
|
||||||
if (!fp) {
|
if (!fp) {
|
||||||
PLOG(ERROR) << "failed to open " << mounts_file;
|
PLOG(ERROR) << "failed to open " << mounts_file;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+24
-24
@@ -250,7 +250,7 @@ static void redirect_stdio(const char* filename) {
|
|||||||
auto start = std::chrono::steady_clock::now();
|
auto start = std::chrono::steady_clock::now();
|
||||||
|
|
||||||
// Child logger to actually write to the log file.
|
// Child logger to actually write to the log file.
|
||||||
FILE* log_fp = fopen(filename, "a");
|
FILE* log_fp = fopen(filename, "ae");
|
||||||
if (log_fp == nullptr) {
|
if (log_fp == nullptr) {
|
||||||
PLOG(ERROR) << "fopen \"" << filename << "\" failed";
|
PLOG(ERROR) << "fopen \"" << filename << "\" failed";
|
||||||
close(pipefd[0]);
|
close(pipefd[0]);
|
||||||
@@ -419,27 +419,27 @@ static void copy_log_file_to_pmsg(const char* source, const char* destination) {
|
|||||||
static off_t tmplog_offset = 0;
|
static off_t tmplog_offset = 0;
|
||||||
|
|
||||||
static void copy_log_file(const char* source, const char* destination, bool append) {
|
static void copy_log_file(const char* source, const char* destination, bool append) {
|
||||||
FILE* dest_fp = fopen_path(destination, append ? "a" : "w");
|
FILE* dest_fp = fopen_path(destination, append ? "ae" : "we");
|
||||||
if (dest_fp == nullptr) {
|
if (dest_fp == nullptr) {
|
||||||
PLOG(ERROR) << "Can't open " << destination;
|
PLOG(ERROR) << "Can't open " << destination;
|
||||||
} else {
|
} else {
|
||||||
FILE* source_fp = fopen(source, "r");
|
FILE* source_fp = fopen(source, "re");
|
||||||
if (source_fp != nullptr) {
|
if (source_fp != nullptr) {
|
||||||
if (append) {
|
if (append) {
|
||||||
fseeko(source_fp, tmplog_offset, SEEK_SET); // Since last write
|
fseeko(source_fp, tmplog_offset, SEEK_SET); // Since last write
|
||||||
}
|
}
|
||||||
char buf[4096];
|
char buf[4096];
|
||||||
size_t bytes;
|
size_t bytes;
|
||||||
while ((bytes = fread(buf, 1, sizeof(buf), source_fp)) != 0) {
|
while ((bytes = fread(buf, 1, sizeof(buf), source_fp)) != 0) {
|
||||||
fwrite(buf, 1, bytes, dest_fp);
|
fwrite(buf, 1, bytes, dest_fp);
|
||||||
}
|
}
|
||||||
if (append) {
|
if (append) {
|
||||||
tmplog_offset = ftello(source_fp);
|
tmplog_offset = ftello(source_fp);
|
||||||
}
|
}
|
||||||
check_and_fclose(source_fp, source);
|
check_and_fclose(source_fp, source);
|
||||||
}
|
|
||||||
check_and_fclose(dest_fp, destination);
|
|
||||||
}
|
}
|
||||||
|
check_and_fclose(dest_fp, destination);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void copy_logs() {
|
static void copy_logs() {
|
||||||
@@ -488,7 +488,7 @@ static void finish_recovery() {
|
|||||||
if (!locale.empty() && has_cache) {
|
if (!locale.empty() && has_cache) {
|
||||||
LOG(INFO) << "Saving locale \"" << locale << "\"";
|
LOG(INFO) << "Saving locale \"" << locale << "\"";
|
||||||
|
|
||||||
FILE* fp = fopen_path(LOCALE_FILE, "w");
|
FILE* fp = fopen_path(LOCALE_FILE, "we");
|
||||||
if (!android::base::WriteStringToFd(locale, fileno(fp))) {
|
if (!android::base::WriteStringToFd(locale, fileno(fp))) {
|
||||||
PLOG(ERROR) << "Failed to save locale to " << LOCALE_FILE;
|
PLOG(ERROR) << "Failed to save locale to " << LOCALE_FILE;
|
||||||
}
|
}
|
||||||
@@ -552,7 +552,7 @@ static bool erase_volume(const char* volume) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string data(sb.st_size, '\0');
|
std::string data(sb.st_size, '\0');
|
||||||
FILE* f = fopen(path.c_str(), "rb");
|
FILE* f = fopen(path.c_str(), "rbe");
|
||||||
fread(&data[0], 1, data.size(), f);
|
fread(&data[0], 1, data.size(), f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
@@ -580,7 +580,7 @@ static bool erase_volume(const char* volume) {
|
|||||||
ui->Print("Failed to make convert_fbe dir %s\n", strerror(errno));
|
ui->Print("Failed to make convert_fbe dir %s\n", strerror(errno));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
FILE* f = fopen(CONVERT_FBE_FILE, "wb");
|
FILE* f = fopen(CONVERT_FBE_FILE, "wbe");
|
||||||
if (!f) {
|
if (!f) {
|
||||||
ui->Print("Failed to convert to file encryption %s\n", strerror(errno));
|
ui->Print("Failed to convert to file encryption %s\n", strerror(errno));
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -485,7 +485,7 @@ TEST_F(UpdaterTest, block_image_update) {
|
|||||||
UpdaterInfo updater_info;
|
UpdaterInfo updater_info;
|
||||||
updater_info.package_zip = handle;
|
updater_info.package_zip = handle;
|
||||||
TemporaryFile temp_pipe;
|
TemporaryFile temp_pipe;
|
||||||
updater_info.cmd_pipe = fopen(temp_pipe.path, "wb");
|
updater_info.cmd_pipe = fopen(temp_pipe.path, "wbe");
|
||||||
updater_info.package_zip_addr = map.addr;
|
updater_info.package_zip_addr = map.addr;
|
||||||
updater_info.package_zip_len = map.length;
|
updater_info.package_zip_len = map.length;
|
||||||
|
|
||||||
@@ -561,7 +561,7 @@ TEST_F(UpdaterTest, new_data_short_write) {
|
|||||||
UpdaterInfo updater_info;
|
UpdaterInfo updater_info;
|
||||||
updater_info.package_zip = handle;
|
updater_info.package_zip = handle;
|
||||||
TemporaryFile temp_pipe;
|
TemporaryFile temp_pipe;
|
||||||
updater_info.cmd_pipe = fopen(temp_pipe.path, "wb");
|
updater_info.cmd_pipe = fopen(temp_pipe.path, "wbe");
|
||||||
updater_info.package_zip_addr = map.addr;
|
updater_info.package_zip_addr = map.addr;
|
||||||
updater_info.package_zip_len = map.length;
|
updater_info.package_zip_len = map.length;
|
||||||
|
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ class ResourceTest : public testing::TestWithParam<std::string> {
|
|||||||
// under recovery.
|
// under recovery.
|
||||||
void SetUp() override {
|
void SetUp() override {
|
||||||
std::string file_path = GetParam();
|
std::string file_path = GetParam();
|
||||||
fp = fopen(file_path.c_str(), "rb");
|
fp = fopen(file_path.c_str(), "rbe");
|
||||||
ASSERT_NE(nullptr, fp);
|
ASSERT_NE(nullptr, fp);
|
||||||
|
|
||||||
unsigned char header[8];
|
unsigned char header[8];
|
||||||
|
|||||||
+72
-73
@@ -474,81 +474,80 @@ std::unique_ptr<EC_KEY, ECKEYDeleter> parse_ec_key(FILE* file) {
|
|||||||
// Otherwise returns false if the file failed to parse, or if it contains zero
|
// Otherwise returns false if the file failed to parse, or if it contains zero
|
||||||
// keys. The contents in certs would be unspecified on failure.
|
// keys. The contents in certs would be unspecified on failure.
|
||||||
bool load_keys(const char* filename, std::vector<Certificate>& certs) {
|
bool load_keys(const char* filename, std::vector<Certificate>& certs) {
|
||||||
std::unique_ptr<FILE, decltype(&fclose)> f(fopen(filename, "r"), fclose);
|
std::unique_ptr<FILE, decltype(&fclose)> f(fopen(filename, "re"), fclose);
|
||||||
if (!f) {
|
if (!f) {
|
||||||
PLOG(ERROR) << "error opening " << filename;
|
PLOG(ERROR) << "error opening " << filename;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
certs.emplace_back(0, Certificate::KEY_TYPE_RSA, nullptr, nullptr);
|
||||||
|
Certificate& cert = certs.back();
|
||||||
|
uint32_t exponent = 0;
|
||||||
|
|
||||||
|
char start_char;
|
||||||
|
if (fscanf(f.get(), " %c", &start_char) != 1) return false;
|
||||||
|
if (start_char == '{') {
|
||||||
|
// a version 1 key has no version specifier.
|
||||||
|
cert.key_type = Certificate::KEY_TYPE_RSA;
|
||||||
|
exponent = 3;
|
||||||
|
cert.hash_len = SHA_DIGEST_LENGTH;
|
||||||
|
} else if (start_char == 'v') {
|
||||||
|
int version;
|
||||||
|
if (fscanf(f.get(), "%d {", &version) != 1) return false;
|
||||||
|
switch (version) {
|
||||||
|
case 2:
|
||||||
|
cert.key_type = Certificate::KEY_TYPE_RSA;
|
||||||
|
exponent = 65537;
|
||||||
|
cert.hash_len = SHA_DIGEST_LENGTH;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
cert.key_type = Certificate::KEY_TYPE_RSA;
|
||||||
|
exponent = 3;
|
||||||
|
cert.hash_len = SHA256_DIGEST_LENGTH;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
cert.key_type = Certificate::KEY_TYPE_RSA;
|
||||||
|
exponent = 65537;
|
||||||
|
cert.hash_len = SHA256_DIGEST_LENGTH;
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
cert.key_type = Certificate::KEY_TYPE_EC;
|
||||||
|
cert.hash_len = SHA256_DIGEST_LENGTH;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cert.key_type == Certificate::KEY_TYPE_RSA) {
|
||||||
|
cert.rsa = parse_rsa_key(f.get(), exponent);
|
||||||
|
if (!cert.rsa) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG(INFO) << "read key e=" << exponent << " hash=" << cert.hash_len;
|
||||||
|
} else if (cert.key_type == Certificate::KEY_TYPE_EC) {
|
||||||
|
cert.ec = parse_ec_key(f.get());
|
||||||
|
if (!cert.ec) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
LOG(ERROR) << "Unknown key type " << cert.key_type;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (true) {
|
// if the line ends in a comma, this file has more keys.
|
||||||
certs.emplace_back(0, Certificate::KEY_TYPE_RSA, nullptr, nullptr);
|
int ch = fgetc(f.get());
|
||||||
Certificate& cert = certs.back();
|
if (ch == ',') {
|
||||||
uint32_t exponent = 0;
|
// more keys to come.
|
||||||
|
continue;
|
||||||
char start_char;
|
} else if (ch == EOF) {
|
||||||
if (fscanf(f.get(), " %c", &start_char) != 1) return false;
|
break;
|
||||||
if (start_char == '{') {
|
} else {
|
||||||
// a version 1 key has no version specifier.
|
LOG(ERROR) << "unexpected character between keys";
|
||||||
cert.key_type = Certificate::KEY_TYPE_RSA;
|
return false;
|
||||||
exponent = 3;
|
|
||||||
cert.hash_len = SHA_DIGEST_LENGTH;
|
|
||||||
} else if (start_char == 'v') {
|
|
||||||
int version;
|
|
||||||
if (fscanf(f.get(), "%d {", &version) != 1) return false;
|
|
||||||
switch (version) {
|
|
||||||
case 2:
|
|
||||||
cert.key_type = Certificate::KEY_TYPE_RSA;
|
|
||||||
exponent = 65537;
|
|
||||||
cert.hash_len = SHA_DIGEST_LENGTH;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
cert.key_type = Certificate::KEY_TYPE_RSA;
|
|
||||||
exponent = 3;
|
|
||||||
cert.hash_len = SHA256_DIGEST_LENGTH;
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
cert.key_type = Certificate::KEY_TYPE_RSA;
|
|
||||||
exponent = 65537;
|
|
||||||
cert.hash_len = SHA256_DIGEST_LENGTH;
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
cert.key_type = Certificate::KEY_TYPE_EC;
|
|
||||||
cert.hash_len = SHA256_DIGEST_LENGTH;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cert.key_type == Certificate::KEY_TYPE_RSA) {
|
|
||||||
cert.rsa = parse_rsa_key(f.get(), exponent);
|
|
||||||
if (!cert.rsa) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
LOG(INFO) << "read key e=" << exponent << " hash=" << cert.hash_len;
|
|
||||||
} else if (cert.key_type == Certificate::KEY_TYPE_EC) {
|
|
||||||
cert.ec = parse_ec_key(f.get());
|
|
||||||
if (!cert.ec) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
LOG(ERROR) << "Unknown key type " << cert.key_type;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if the line ends in a comma, this file has more keys.
|
|
||||||
int ch = fgetc(f.get());
|
|
||||||
if (ch == ',') {
|
|
||||||
// more keys to come.
|
|
||||||
continue;
|
|
||||||
} else if (ch == EOF) {
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
LOG(ERROR) << "unexpected character between keys";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user