Skip to content

Commit

Permalink
fix(userspace/libsinsp): avoid possible UB when calling back or `fr…
Browse files Browse the repository at this point in the history
…ont` without checking string emptiness.

Signed-off-by: Federico Di Pierro <[email protected]>
  • Loading branch information
FedeDP committed Sep 30, 2024
1 parent 8baec4b commit bef6c42
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion userspace/libsinsp/parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2384,7 +2384,7 @@ std::string sinsp_parser::parse_dirfd(sinsp_evt *evt, std::string_view name, int
return "<UNKNOWN>";
}

if(fdinfo->m_name.back() == '/') {
if(!fdinfo->m_name.empty() && fdinfo->m_name.back() == '/') {
return fdinfo->m_name;
}
return fdinfo->m_name + '/';
Expand Down
2 changes: 1 addition & 1 deletion userspace/libsinsp/sinsp_filtercheck_fdlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ uint8_t *sinsp_filter_check_fdlist::extract_single(sinsp_evt *evt,
pos += 10;
}

if(m_strval.size() != 0) {
if(!m_strval.empty()) {
if(m_strval.back() == ',') {
m_strval = m_strval.substr(0, m_strval.size() - 1);
}
Expand Down
2 changes: 1 addition & 1 deletion userspace/libsinsp/sinsp_filtercheck_fspath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ static inline std::string format_dirfd(sinsp_evt* evt) {
return "<UNKNOWN>";
}

if(fd_info_dirfd->m_name.back() == '/') {
if(!fd_info_dirfd->m_name.empty() && fd_info_dirfd->m_name.back() == '/') {
return fd_info_dirfd->m_name;
}

Expand Down

0 comments on commit bef6c42

Please sign in to comment.