Skip to content

Commit

Permalink
fix(libsinsp): adjust g_invalidchar to allow emojis, cyrillic, chines…
Browse files Browse the repository at this point in the history
…e etc

Signed-off-by: Melissa Kilby <[email protected]>
  • Loading branch information
incertum committed Dec 10, 2023
1 parent 4788825 commit 12a686e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
17 changes: 16 additions & 1 deletion userspace/libsinsp/test/sinsp_utils.ut.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright (C) 2023 The Falco Authors.
Copyright (C) 2023 The Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -123,4 +123,19 @@ TEST(sinsp_utils_test, concatenate_paths)
path2 = "////app";
res = sinsp_utils::concatenate_paths(path1, path2);
EXPECT_EQ("/app", res);

path1 = "/root/";
path2 = "../😉";
res = sinsp_utils::concatenate_paths(path1, path2);
EXPECT_EQ("/😉", res);

path1 = "/root/";
path2 = "../诶比西";
res = sinsp_utils::concatenate_paths(path1, path2);
EXPECT_EQ("/诶比西", res);

path1 = "/root/";
path2 = "../АБВЙЛж";
res = sinsp_utils::concatenate_paths(path1, path2);
EXPECT_EQ("/АБВЙЛж", res);
}
15 changes: 6 additions & 9 deletions userspace/libsinsp/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,12 @@ class sinsp_utils

struct g_invalidchar
{
bool operator()(char c) const
{
if(c < -1)
{
return true;
}

return !isprint((unsigned)c);
}
bool operator()(char c) const
{
// Exclude all non-printable characters and control characters while
// including a wide range of languages (emojis, cyrillic, chinese etc)
return !(isprint((unsigned)c) || (c < 0));
}
};

inline void sanitize_string(std::string &str)
Expand Down

0 comments on commit 12a686e

Please sign in to comment.