steamcompmgr: Make get_appid_from_pid more robust

Was some undefined value ptrs going on here, and not checking if the PID stat opened successfully.
This commit is contained in:
Joshua Ashton 2022-11-21 03:45:21 +00:00 committed by Joshie
parent f4f0239b31
commit 48d726c72b

View file

@ -3382,12 +3382,16 @@ get_appid_from_pid( pid_t pid )
{
snprintf( filename, sizeof( filename ), "/proc/%i/stat", next_pid );
std::ifstream proc_stat_file( filename );
if (!proc_stat_file.is_open() || proc_stat_file.bad())
break;
std::string proc_stat;
std::getline( proc_stat_file, proc_stat );
char *procName = nullptr;
char *lastParens;
char *lastParens = nullptr;
for ( uint32_t i = 0; i < proc_stat.length(); i++ )
{
@ -3402,6 +3406,9 @@ get_appid_from_pid( pid_t pid )
}
}
if (!lastParens)
break;
*lastParens = '\0';
char state;
int parent_pid = -1;