app-i18n/mozc: Verion bump (2.26.4632_p20220213064411_p20220214004422).
[gentoo-zh.git] / app-i18n / mozc / files / mozc-2.26.4632-server_path_check.patch
blobf2f53ae4c766e292c3144316c0e878bd2ff7240e
1 https://github.com/google/mozc/issues/471
3 --- a/src/ipc/ipc_path_manager.cc 2021-12-03 23:31:50.000000000 +0800
4 +++ b/src/ipc/ipc_path_manager.cc 2022-06-19 21:15:01.871580323 +0800
5 @@ -345,9 +345,21 @@
6 return false;
9 + // Expand symbolic links in the expected server path to avoid false negatives
10 + // during comparisons of the expected server path and the actual server path.
11 + string real_server_path = server_path;
12 +#ifndef OS_WIN
13 + char real_server_path_[PATH_MAX];
14 + if (realpath(server_path.c_str(), real_server_path_) == NULL) {
15 + LOG(ERROR) << "realpath failed: " << strerror(errno);
16 + return false;
17 + }
18 + real_server_path = real_server_path_;
19 +#endif
21 // compare path name
22 if (pid == server_pid_) {
23 - return (server_path == server_path_);
24 + return (real_server_path == server_path_);
27 server_pid_ = 0;
28 @@ -357,17 +369,17 @@
30 std::wstring expected_server_ntpath;
31 const std::map<std::string, std::wstring>::const_iterator it =
32 - expected_server_ntpath_cache_.find(server_path);
33 + expected_server_ntpath_cache_.find(real_server_path);
34 if (it != expected_server_ntpath_cache_.end()) {
35 expected_server_ntpath = it->second;
36 } else {
37 std::wstring wide_server_path;
38 - Util::Utf8ToWide(server_path, &wide_server_path);
39 + Util::UTF8ToWide(real_server_path, &wide_server_path);
40 if (WinUtil::GetNtPath(wide_server_path, &expected_server_ntpath)) {
41 - // Caches the relationship from |server_path| to
42 - // |expected_server_ntpath| in case |server_path| is renamed later.
43 + // Caches the relationship from |real_server_path| to
44 + // |expected_server_ntpath| in case |real_server_path| is renamed later.
45 // (This can happen during the updating).
46 - expected_server_ntpath_cache_[server_path] = expected_server_ntpath;
47 + expected_server_ntpath_cache_[real_server_path] = expected_server_ntpath;
51 @@ -384,9 +396,9 @@
52 return false;
55 - // Here we can safely assume that |server_path| (expected one) should be
56 + // Here we can safely assume that |real_server_path| (expected one) should be
57 // the same to |server_path_| (actual one).
58 - server_path_ = server_path;
59 + server_path_ = real_server_path;
60 server_pid_ = pid;
62 #endif // OS_WIN
63 @@ -411,7 +423,7 @@
64 #ifdef OS_LINUX
65 // load from /proc/<pid>/exe
66 char proc[128];
67 - char filename[512];
68 + char filename[PATH_MAX];
69 absl::SNPrintF(proc, sizeof(proc) - 1, "/proc/%u/exe", pid);
70 const ssize_t size = readlink(proc, filename, sizeof(filename) - 1);
71 if (size == -1) {
72 @@ -424,18 +436,18 @@
73 server_pid_ = pid;
74 #endif // OS_LINUX
76 - VLOG(1) << "server path: " << server_path << " " << server_path_;
77 - if (server_path == server_path_) {
78 + VLOG(1) << "server path: " << real_server_path << " " << server_path_;
79 + if (real_server_path == server_path_) {
80 return true;
83 #ifdef OS_LINUX
84 - if ((server_path + " (deleted)") == server_path_) {
85 - LOG(WARNING) << server_path << " on disk is modified";
86 + if ((real_server_path + " (deleted)") == server_path_) {
87 + LOG(WARNING) << real_server_path << " on disk is modified";
88 // If a user updates the server binary on disk during the server is running,
89 // "readlink /proc/<pid>/exe" returns a path with the " (deleted)" suffix.
90 // We allow the special case.
91 - server_path_ = server_path;
92 + server_path_ = real_server_path;
93 return true;
95 #endif // OS_LINUX