From 48d726c72b096b23b82c6ad745bfc0f4c7e082a7 Mon Sep 17 00:00:00 2001 From: Joshua Ashton Date: Mon, 21 Nov 2022 03:45:21 +0000 Subject: [PATCH] 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. --- src/steamcompmgr.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp index df5409b..cab8e51 100644 --- a/src/steamcompmgr.cpp +++ b/src/steamcompmgr.cpp @@ -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;