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
This commit is contained in:
parent
0142b3c166
commit
9f1be12b9a
6
lmkd.cpp
6
lmkd.cpp
|
|
@ -1150,9 +1150,10 @@ static void cmd_procprio(LMKD_CTRL_PACKET packet, int field_count, struct ucred
|
|||
} 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);
|
||||
|
|
@ -1187,9 +1188,10 @@ static void cmd_procremove(LMKD_CTRL_PACKET packet, struct ucred *cred) {
|
|||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -262,7 +262,7 @@ void stats_remove_taskname(int pid) {
|
|||
}
|
||||
|
||||
void stats_store_taskname(int pid, const char* taskname) {
|
||||
if (!enable_stats_log) {
|
||||
if (!enable_stats_log || !taskname) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue