Skip to content

Commit

Permalink
cleanup(sinsp): remove some dead code
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Terzolo <[email protected]>
  • Loading branch information
Andreagit97 authored and poiana committed Dec 18, 2023
1 parent e6db0e6 commit 0754fba
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 29 deletions.
30 changes: 1 addition & 29 deletions userspace/libsinsp/sinsp_filtercheck_fd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,35 +341,7 @@ uint8_t* sinsp_filter_check_fd::extract_from_null_fd(sinsp_evt *evt, OUT uint32_
}
case TYPE_FILENAME:
{
if(evt->get_type() != PPME_SYSCALL_OPEN_E && evt->get_type() != PPME_SYSCALL_OPENAT_E &&
evt->get_type() != PPME_SYSCALL_OPENAT_2_E && evt->get_type() != PPME_SYSCALL_OPENAT2_E &&
evt->get_type() != PPME_SYSCALL_CREAT_E)
{
return NULL;
}

if(extract_fdname_from_creator(evt, len, sanitize_strings) == true)
{
if(sanitize_strings)
{
sanitize_string(m_tstr);
}

size_t pos = m_tstr.rfind('/');
if(pos != string::npos)
{
if(pos < m_tstr.size() - 1)
{
m_tstr = m_tstr.substr(pos + 1, string::npos);
}
}

RETURN_EXTRACT_STRING(m_tstr);
}
else
{
return NULL;
}
return NULL;
}
case TYPE_FDTYPECHAR:
*len = 1;
Expand Down
47 changes: 47 additions & 0 deletions userspace/libsinsp/test/filterchecks/fd.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright (C) 2023 The Falco Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#include <test/helpers/threads_helpers.h>

TEST_F(sinsp_with_test_input, FD_FILTER_extract_from_null_type_filename)
{
add_default_init_thread();

open_inspector();

std::string path = "/home/file.txt";
int64_t fd = 3;
int64_t dirfd = 4;

auto evt = add_event_advance_ts(increasing_ts(), INIT_TID, PPME_SYSCALL_OPEN_E, fd, path.c_str(),
(uint32_t)PPM_O_RDWR | PPM_O_CREAT, (uint32_t)0);
ASSERT_FALSE(field_has_value(evt, "fd.filename"));

evt = add_event_advance_ts(increasing_ts(), INIT_TID, PPME_SYSCALL_OPENAT_2_E, 4, dirfd, path.c_str(), 0, 0);
ASSERT_FALSE(field_has_value(evt, "fd.filename"));

evt = add_event_advance_ts(increasing_ts(), INIT_TID, PPME_SYSCALL_OPENAT2_E, 5, dirfd, path.c_str(), 0, 0, 0);
ASSERT_FALSE(field_has_value(evt, "fd.filename"));

evt = add_event_advance_ts(increasing_ts(), INIT_TID, PPME_SYSCALL_CREAT_E, 2, path.c_str(), 0);
ASSERT_FALSE(field_has_value(evt, "fd.filename"));

evt = add_event_advance_ts(increasing_ts(), INIT_TID, PPME_SYSCALL_OPENAT_E, 4, dirfd, path.c_str(),
PPM_O_RDONLY | PPM_O_CLOEXEC, 0);
ASSERT_FALSE(field_has_value(evt, "fd.filename"));
}

0 comments on commit 0754fba

Please sign in to comment.