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

Added some NULL checks before using strlen(), fixing issue #740 #742

Merged
merged 2 commits into from
Feb 2, 2017
Merged
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
20 changes: 16 additions & 4 deletions userspace/libsinsp/filterchecks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4427,7 +4427,10 @@ uint8_t* sinsp_filter_check_tracer::extract_arg(sinsp_partial_tracer* pae, OUT u
}
}

*len = strlen(res);
if (res)
{
*len = strlen(res);
}
return (uint8_t*)res;
}

Expand Down Expand Up @@ -4541,7 +4544,10 @@ uint8_t* sinsp_filter_check_tracer::extract(sinsp_evt *evt, OUT uint32_t* len, b
}
}

*len = strlen(res);
if(res)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix makes sense since from the if above res may be not initialised, have you found any reasons why? Is it expected?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the m_argid is somehow out of range, res will not get initialized. This is basically the same as some of the code that we crashed on further below. I'm not entirely sure yet why m_argid would be out of range but reading the code it seems acceptable to just return NULL, so the added strlen() should not assume res is set.
In general I'm a big proponent of more defensive programming. In cases like this it would only add very few cycles to sanity check, but may help prevent more core dumps in the future.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes let's do it, for sure more sanity check does not hurt.

{
*len = strlen(res);
}
return (uint8_t*)res;
}
case TYPE_IDTAG:
Expand Down Expand Up @@ -5030,7 +5036,10 @@ inline uint8_t* sinsp_filter_check_evtin::extract_tracer(sinsp_evt *evt, sinsp_p
}
}

*len = strlen(val);
if(val)
{
*len = strlen(val);
}
return (uint8_t*) val;
}
case TYPE_ARGS:
Expand Down Expand Up @@ -5123,7 +5132,10 @@ inline uint8_t* sinsp_filter_check_evtin::extract_tracer(sinsp_evt *evt, sinsp_p
}
}

*len = strlen(val);
if(val)
{
*len = strlen(val);
}
return (uint8_t*) val;
}
default:
Expand Down