Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SMAGENT-768: sinsp::scap_t* could be deref'd before initialization co… #1048

Merged
merged 1 commit into from
Jan 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions userspace/libsinsp/sinsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,16 @@ sinsp_threadinfo* sinsp::get_thread(int64_t tid, bool query_os_if_not_found, boo
#endif
))
{
// Certain code paths can lead to this point from scap_open() (incomplete example:
// scap_proc_scan_proc_dir() -> resolve_container() -> get_env()). Adding a
// defensive check here to protect both, callers of get_env and get_thread.
if (!m_h)
{
g_logger.format(sinsp_logger::SEV_INFO, "%s: Unable to complete for tid=%"
PRIu64 ": sinsp::scap_t* is uninitialized", __func__, tid);
return NULL;
}

scap_threadinfo* scap_proc = NULL;
sinsp_threadinfo newti(this);

Expand Down
1 change: 1 addition & 0 deletions userspace/libsinsp/threadinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ const vector<string>& sinsp_threadinfo::get_env()
else
{
// it should never happen but provide a safe fallback just in case
// except during sinsp::scap_open() (see sinsp::get_thread()).
ASSERT(false);
return m_env;
}
Expand Down