lmkd: Handle cases when proc_get_name() might return NULL
proc_get_name() can return NULL if the corresponding process has died
or open fails with ENOMEM due to memory shortages.
Ensure such cases are handled without NULL pointer access.
Bug: 186157675
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: I05b288e3808bec0bdb73db32de02ba3a322ca6e1
(cherry picked from commit e5995b826942a5cb4b16a6665633beec842bb8d7)
diff --git a/lmkd.cpp b/lmkd.cpp
index c646479..3515fdb 100644
--- a/lmkd.cpp
+++ b/lmkd.cpp
@@ -1157,9 +1157,10 @@
} else {
if (!claim_record(procp, cred->pid)) {
char buf[LINE_MAX];
+ char *taskname = proc_get_name(cred->pid, buf, sizeof(buf));
/* Only registrant of the record can remove it */
ALOGE("%s (%d, %d) attempts to modify a process registered by another client",
- proc_get_name(cred->pid, buf, sizeof(buf)), cred->uid, cred->pid);
+ taskname ? taskname : "A process ", cred->uid, cred->pid);
return;
}
proc_unslot(procp);
@@ -1194,9 +1195,10 @@
if (!claim_record(procp, cred->pid)) {
char buf[LINE_MAX];
+ char *taskname = proc_get_name(cred->pid, buf, sizeof(buf));
/* Only registrant of the record can remove it */
ALOGE("%s (%d, %d) attempts to unregister a process registered by another client",
- proc_get_name(cred->pid, buf, sizeof(buf)), cred->uid, cred->pid);
+ taskname ? taskname : "A process ", cred->uid, cred->pid);
return;
}
diff --git a/statslog.cpp b/statslog.cpp
index a9606f9..410a108 100644
--- a/statslog.cpp
+++ b/statslog.cpp
@@ -260,7 +260,7 @@
}
void stats_store_taskname(int pid, const char* taskname) {
- if (!enable_stats_log) {
+ if (!enable_stats_log || !taskname) {
return;
}