From bf2bebd8e74908317a76c11f1951c67c0910eefb Mon Sep 17 00:00:00 2001 From: "T.J. Mercier" Date: Fri, 21 Jul 2023 00:31:06 +0000 Subject: [PATCH] libprocessgroup: UIDs in linux are unsigned We use the %d format specificier for uid_t, which maps to __kernel_uid32_t, which is unsigned. [1] This is undefined behavior which can lead to paths with negative UIDs when erroneously large values are passed for uid: E libprocessgroup: No such cgroup attribute: /sys/fs/cgroup/uid_-89846/cgroup.freeze Fix it with %u. [1] https://cs.android.com/search?q=typedef.*__kernel_uid32_t&ss=android%2Fplatform%2Fsuperproject%2Fmain Change-Id: Ibb52ba2503e30e2f20770b7d23629167e38d076a --- libprocessgroup/task_profiles.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libprocessgroup/task_profiles.cpp b/libprocessgroup/task_profiles.cpp index 44dba2a16..1276a72a6 100644 --- a/libprocessgroup/task_profiles.cpp +++ b/libprocessgroup/task_profiles.cpp @@ -146,7 +146,7 @@ bool ProfileAttribute::GetPathForUID(uid_t uid, std::string* path) const { const std::string& file_name = controller()->version() == 2 && !file_v2_name_.empty() ? file_v2_name_ : file_name_; - *path = StringPrintf("%s/uid_%d/%s", controller()->path(), uid, file_name.c_str()); + *path = StringPrintf("%s/uid_%u/%s", controller()->path(), uid, file_name.c_str()); return true; }