From 9db0d5490a7a4f90e1303253f3e91efb3d46e19f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 29 Oct 2009 17:40:39 +0000 Subject: [PATCH] more error checking around opening /proc/pid/mem --- library/DFProcess.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/library/DFProcess.cpp b/library/DFProcess.cpp index ccbe55ef4..c3e87e72d 100644 --- a/library/DFProcess.cpp +++ b/library/DFProcess.cpp @@ -117,12 +117,24 @@ bool Process::attach() } cout << "Managed to attach to pid " << my_handle << endl; - attached = true; - g_pProcess = this; - g_ProcessHandle = my_handle; - g_ProcessMemFile = open(memFile.c_str(),O_RDONLY); - cout << "Attach_after_opening /proc/PID/mem" << endl; - return true; // we are attached + int proc_pid_mem = open(memFile.c_str(),O_RDONLY); + if(proc_pid_mem == -1) + { + ptrace(PTRACE_DETACH, my_handle, NULL, NULL); + cerr << "couldn't open /proc/" << my_handle << "/mem" << endl; + perror("open(memFile.c_str(),O_RDONLY)"); + return false; + } + else + { + attached = true; + g_pProcess = this; + g_ProcessHandle = my_handle; + + g_ProcessMemFile = proc_pid_mem; + cout << "Attach_after_opening /proc/PID/mem" << endl; + return true; // we are attached + } } bool Process::detach()