Merge changes I8c6b2d1d,I06e0f759,I95d79809

* changes:
  Add async_safe_format_fd_va_list
  Fix normalize_path's handling of "/.."
  linker: fix invalid zip file handling
This commit is contained in:
Ryan Prichard 2018-10-08 20:29:00 +00:00 committed by Gerrit Code Review
commit cb8ed207d2
5 changed files with 15 additions and 7 deletions

View file

@ -424,13 +424,18 @@ int async_safe_format_buffer(char* buffer, size_t buffer_size, const char* forma
return buffer_len; return buffer_len;
} }
int async_safe_format_fd(int fd, const char* format, ...) { int async_safe_format_fd_va_list(int fd, const char* format, va_list args) {
FdOutputStream os(fd); FdOutputStream os(fd);
out_vformat(os, format, args);
return os.total;
}
int async_safe_format_fd(int fd, const char* format, ...) {
va_list args; va_list args;
va_start(args, format); va_start(args, format);
out_vformat(os, format, args); int result = async_safe_format_fd_va_list(fd, format, args);
va_end(args); va_end(args);
return os.total; return result;
} }
static int write_stderr(const char* tag, const char* msg) { static int write_stderr(const char* tag, const char* msg) {

View file

@ -90,6 +90,7 @@ int async_safe_format_buffer(char* buf, size_t size, const char* fmt, ...) __pri
int async_safe_format_buffer_va_list(char* buffer, size_t buffer_size, const char* format, va_list args); int async_safe_format_buffer_va_list(char* buffer, size_t buffer_size, const char* format, va_list args);
int async_safe_format_fd(int fd, const char* format , ...) __printflike(2, 3); int async_safe_format_fd(int fd, const char* format , ...) __printflike(2, 3);
int async_safe_format_fd_va_list(int fd, const char* format, va_list args);
int async_safe_format_log(int pri, const char* tag, const char* fmt, ...) __printflike(3, 4); int async_safe_format_log(int pri, const char* tag, const char* fmt, ...) __printflike(3, 4);
int async_safe_format_log_va_list(int pri, const char* tag, const char* fmt, va_list ap); int async_safe_format_log_va_list(int pri, const char* tag, const char* fmt, va_list ap);
int async_safe_write_log(int pri, const char* tag, const char* msg); int async_safe_write_log(int pri, const char* tag, const char* msg);

View file

@ -918,8 +918,7 @@ bool ZipArchiveCache::get_or_open(const char* zip_path, ZipArchiveHandle* handle
if (OpenArchiveFd(fd, "", handle) != 0) { if (OpenArchiveFd(fd, "", handle) != 0) {
// invalid zip-file (?) // invalid zip-file (?)
CloseArchive(handle); CloseArchive(*handle);
close(fd);
return false; return false;
} }

View file

@ -98,8 +98,8 @@ bool normalize_path(const char* path, std::string* normalized_path) {
while (out_ptr > buf && *--out_ptr != '/') { while (out_ptr > buf && *--out_ptr != '/') {
} }
if (in_ptr[0] == 0) { if (in_ptr[0] == 0) {
// retain '/' // retain '/' (or write the initial '/' for "/..")
out_ptr++; *out_ptr++ = '/';
} }
continue; continue;
} }

View file

@ -58,6 +58,9 @@ TEST(linker_utils, normalize_path_smoke) {
ASSERT_TRUE(normalize_path("/a/../../b", &output)); ASSERT_TRUE(normalize_path("/a/../../b", &output));
ASSERT_EQ("/b", output); ASSERT_EQ("/b", output);
ASSERT_TRUE(normalize_path("/..", &output));
ASSERT_EQ("/", output);
output = "unchanged"; output = "unchanged";
ASSERT_FALSE(normalize_path("root///dir/.///dir2/somedir/../zipfile!/dir/dir9//..///afile", &output)); ASSERT_FALSE(normalize_path("root///dir/.///dir2/somedir/../zipfile!/dir/dir9//..///afile", &output));
ASSERT_EQ("unchanged", output); ASSERT_EQ("unchanged", output);