Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
8528ff22
Unverified
Commit
8528ff22
authored
Nov 21, 2020
by
Dominik Charousset
Committed by
GitHub
Nov 21, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1166
Fix unsafe use of strncmp
parents
0221960c
97f30de1
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
68 additions
and
32 deletions
+68
-32
.ci/run.sh
.ci/run.sh
+30
-2
CHANGELOG.md
CHANGELOG.md
+1
-0
Jenkinsfile
Jenkinsfile
+8
-3
libcaf_core/src/string_view.cpp
libcaf_core/src/string_view.cpp
+12
-10
libcaf_core/test/string_view.cpp
libcaf_core/test/string_view.cpp
+17
-17
No files found.
.ci/run.sh
View file @
8528ff22
...
@@ -28,8 +28,9 @@ elif [ $# = 2 ]; then
...
@@ -28,8 +28,9 @@ elif [ $# = 2 ]; then
if
[
"
$1
"
=
'test'
]
&&
[
-d
"
$2
"
]
;
then
if
[
"
$1
"
=
'test'
]
&&
[
-d
"
$2
"
]
;
then
Mode
=
'test'
Mode
=
'test'
BuildDir
=
"
$2
"
BuildDir
=
"
$2
"
elif
[
"
$1
"
=
'assert'
]
&&
[
"
$2
"
=
'LeakSanitizer'
]
;
then
elif
[
"
$1
"
=
'assert'
]
;
then
Mode
=
'assert'
Mode
=
'assert'
What
=
"
$2
"
else
else
usage
usage
fi
fi
...
@@ -85,10 +86,37 @@ runLeakSanitizerCheck() {
...
@@ -85,10 +86,37 @@ runLeakSanitizerCheck() {
fi
fi
}
}
runUBSanitizerCheck
()
{
UBSanCheckStr
=
"
int main(int argc, char**) {
int k = 0x7fffffff;
k += argc;
return 0;
}
"
echo
"
${
UBSanCheckStr
}
"
>
UBSanCheck.cpp
c++ UBSanCheck.cpp
-o
UBSanCheck
-fsanitize
=
undefined
-fno-omit-frame-pointer
out
=
`
./UBSanCheck 2>&1 |
grep
-o
'signed integer overflow'
`
if
[
-z
"
$out
"
]
;
then
echo
"unable to detected undefined behavior on this platform!"
return
1
fi
}
if
[
"
$Mode
"
=
'build'
]
;
then
if
[
"
$Mode
"
=
'build'
]
;
then
runBuild
runBuild
elif
[
"
$Mode
"
=
'test'
]
;
then
elif
[
"
$Mode
"
=
'test'
]
;
then
runTest
runTest
else
else
runLeakSanitizerCheck
case
"
$What
"
in
LeakSanitizer
)
runLeakSanitizerCheck
;;
UBSanitizer
)
runUBSanitizerCheck
;;
*
)
echo
"unrecognized tag:
$What
!"
return
1
esac
fi
fi
CHANGELOG.md
View file @
8528ff22
...
@@ -48,6 +48,7 @@ is based on [Keep a Changelog](https://keepachangelog.com).
...
@@ -48,6 +48,7 @@ is based on [Keep a Changelog](https://keepachangelog.com).
console output.
console output.
-
Fix memory leaks when deserializing URIs and when detaching the content of
-
Fix memory leaks when deserializing URIs and when detaching the content of
messages (#1160).
messages (#1160).
-
Fix undefined behavior in
`string_view::compare`
(#1164).
## [0.18.0-rc.1] - 2020-09-09
## [0.18.0-rc.1] - 2020-09-09
...
...
Jenkinsfile
View file @
8528ff22
...
@@ -93,13 +93,18 @@ config = [
...
@@ -93,13 +93,18 @@ config = [
'ASAN_OPTIONS=detect_leaks=1'
,
'ASAN_OPTIONS=detect_leaks=1'
,
],
],
]],
]],
// One extra debug build with static libraries.
// One extra debug build with static libraries
and UBSanitizer
.
[
'
debian-10
'
,
[
[
'
fedora-32
'
,
[
numCores:
4
,
numCores:
4
,
tags:
[
'docker'
],
tags:
[
'docker'
,
'UBSanitizer'
],
builds:
[
'debug'
],
builds:
[
'debug'
],
extraBuildFlags:
[
extraBuildFlags:
[
'BUILD_SHARED_LIBS:BOOL=OFF'
,
'BUILD_SHARED_LIBS:BOOL=OFF'
,
'CAF_SANITIZERS:STRING=address,undefined'
,
],
extraBuildEnv:
[
'CXXFLAGS=-fno-sanitize-recover=undefined'
,
'LDFLAGS=-fno-sanitize-recover=undefined'
,
],
],
]],
]],
// Other UNIX systems.
// Other UNIX systems.
...
...
libcaf_core/src/string_view.cpp
View file @
8528ff22
...
@@ -102,16 +102,18 @@ string_view string_view::substr(size_type pos, size_type n) const noexcept {
...
@@ -102,16 +102,18 @@ string_view string_view::substr(size_type pos, size_type n) const noexcept {
}
}
int
string_view
::
compare
(
string_view
str
)
const
noexcept
{
int
string_view
::
compare
(
string_view
str
)
const
noexcept
{
auto
s0
=
size
();
// TODO: use lexicographical_compare_three_way when switching to C++20
auto
s1
=
str
.
size
();
auto
i0
=
begin
();
auto
fallback
=
[](
int
x
,
int
y
)
{
auto
e0
=
end
();
return
x
==
0
?
y
:
x
;
auto
i1
=
str
.
begin
();
};
auto
e1
=
str
.
end
();
if
(
s0
==
s1
)
while
(
i0
!=
e0
&&
i1
!=
e1
)
return
strncmp
(
data
(),
str
.
data
(),
s0
);
if
(
auto
diff
=
*
i0
++
-
*
i1
++
;
diff
!=
0
)
else
if
(
s0
<
s1
)
return
diff
;
return
fallback
(
strncmp
(
data
(),
str
.
data
(),
s0
),
-
1
);
if
(
i0
==
e0
)
return
fallback
(
strncmp
(
data
(),
str
.
data
(),
s1
),
1
);
return
i1
!=
e1
?
-
1
:
0
;
else
return
i1
==
e1
?
1
:
0
;
}
}
int
string_view
::
compare
(
size_type
pos1
,
size_type
n1
,
int
string_view
::
compare
(
size_type
pos1
,
size_type
n1
,
...
...
libcaf_core/test/string_view.cpp
View file @
8528ff22
...
@@ -23,6 +23,7 @@
...
@@ -23,6 +23,7 @@
#include "core-test.hpp"
#include "core-test.hpp"
using
namespace
caf
;
using
namespace
caf
;
using
namespace
caf
::
literals
;
CAF_TEST
(
default
construction
)
{
CAF_TEST
(
default
construction
)
{
string_view
x
;
string_view
x
;
...
@@ -34,7 +35,7 @@ CAF_TEST(default construction) {
...
@@ -34,7 +35,7 @@ CAF_TEST(default construction) {
}
}
CAF_TEST
(
cstring
conversion
)
{
CAF_TEST
(
cstring
conversion
)
{
string_view
x
=
"abc"
;
auto
x
=
"abc"
_sv
;
CAF_CHECK_EQUAL
(
x
.
size
(),
3u
);
CAF_CHECK_EQUAL
(
x
.
size
(),
3u
);
CAF_CHECK_EQUAL
(
x
[
0
],
'a'
);
CAF_CHECK_EQUAL
(
x
[
0
],
'a'
);
CAF_CHECK_EQUAL
(
x
[
1
],
'b'
);
CAF_CHECK_EQUAL
(
x
[
1
],
'b'
);
...
@@ -50,14 +51,12 @@ CAF_TEST(string conversion) {
...
@@ -50,14 +51,12 @@ CAF_TEST(string conversion) {
string_view
y
;
string_view
y
;
y
=
x
;
y
=
x
;
CAF_CHECK_EQUAL
(
x
,
y
);
CAF_CHECK_EQUAL
(
x
,
y
);
auto
f
=
[
&
](
string_view
z
)
{
auto
f
=
[
&
](
string_view
z
)
{
CAF_CHECK_EQUAL
(
x
,
z
);
};
CAF_CHECK_EQUAL
(
x
,
z
);
};
f
(
x
);
f
(
x
);
}
}
CAF_TEST
(
substrings
)
{
CAF_TEST
(
substrings
)
{
string_view
x
=
"abcdefghi"
;
auto
x
=
"abcdefghi"
_sv
;
CAF_CHECK
(
x
.
remove_prefix
(
3
),
"defghi"
);
CAF_CHECK
(
x
.
remove_prefix
(
3
),
"defghi"
);
CAF_CHECK
(
x
.
remove_suffix
(
3
),
"abcdef"
);
CAF_CHECK
(
x
.
remove_suffix
(
3
),
"abcdef"
);
CAF_CHECK
(
x
.
substr
(
3
,
3
),
"def"
);
CAF_CHECK
(
x
.
substr
(
3
,
3
),
"def"
);
...
@@ -69,9 +68,9 @@ CAF_TEST(substrings) {
...
@@ -69,9 +68,9 @@ CAF_TEST(substrings) {
CAF_TEST
(
compare
)
{
CAF_TEST
(
compare
)
{
// testees
// testees
string_view
x
=
"abc"
;
auto
x
=
"abc"
_sv
;
string_view
y
=
"bcd"
;
auto
y
=
"bcd"
_sv
;
string_view
z
=
"cde"
;
auto
z
=
"cde"
_sv
;
// x.compare full strings
// x.compare full strings
CAF_CHECK
(
x
.
compare
(
"abc"
)
==
0
);
CAF_CHECK
(
x
.
compare
(
"abc"
)
==
0
);
CAF_CHECK
(
x
.
compare
(
y
)
<
0
);
CAF_CHECK
(
x
.
compare
(
y
)
<
0
);
...
@@ -88,14 +87,15 @@ CAF_TEST(compare) {
...
@@ -88,14 +87,15 @@ CAF_TEST(compare) {
CAF_CHECK
(
x
.
compare
(
0
,
3
,
"abc"
)
==
0
);
CAF_CHECK
(
x
.
compare
(
0
,
3
,
"abc"
)
==
0
);
CAF_CHECK
(
x
.
compare
(
1
,
2
,
y
,
0
,
2
)
==
0
);
CAF_CHECK
(
x
.
compare
(
1
,
2
,
y
,
0
,
2
)
==
0
);
CAF_CHECK
(
x
.
compare
(
2
,
1
,
z
,
0
,
1
)
==
0
);
CAF_CHECK
(
x
.
compare
(
2
,
1
,
z
,
0
,
1
)
==
0
);
CAF_CHECK
(
x
.
compare
(
2
,
1
,
z
,
0
,
1
)
==
0
);
// make sure substrings aren't equal
// make sure substrings aren't equal
CAF_CHECK
(
string_view
(
"a/"
)
!=
string_view
(
"a/b"
));
CAF_CHECK
(
"a/"
_sv
!=
"a/b"
_sv
);
CAF_CHECK
(
z
.
compare
(
"cdef"
_sv
)
<
0
);
CAF_CHECK
(
"cdef"
_sv
.
compare
(
z
)
>
0
);
}
}
CAF_TEST
(
copy
)
{
CAF_TEST
(
copy
)
{
char
buf
[
10
];
char
buf
[
10
];
string_view
str
=
"hello"
;
auto
str
=
"hello"
_sv
;
auto
n
=
str
.
copy
(
buf
,
str
.
size
());
auto
n
=
str
.
copy
(
buf
,
str
.
size
());
CAF_CHECK_EQUAL
(
n
,
5u
);
CAF_CHECK_EQUAL
(
n
,
5u
);
buf
[
n
]
=
'\0'
;
buf
[
n
]
=
'\0'
;
...
@@ -109,7 +109,7 @@ CAF_TEST(copy) {
...
@@ -109,7 +109,7 @@ CAF_TEST(copy) {
CAF_TEST
(
find
)
{
CAF_TEST
(
find
)
{
// Check whether string_view behaves exactly like std::string.
// Check whether string_view behaves exactly like std::string.
string_view
x
=
"abcdef"
;
auto
x
=
"abcdef"
_sv
;
std
::
string
y
=
"abcdef"
;
std
::
string
y
=
"abcdef"
;
CAF_CHECK_EQUAL
(
x
.
find
(
'a'
),
y
.
find
(
'a'
));
CAF_CHECK_EQUAL
(
x
.
find
(
'a'
),
y
.
find
(
'a'
));
CAF_CHECK_EQUAL
(
x
.
find
(
'b'
),
y
.
find
(
'b'
));
CAF_CHECK_EQUAL
(
x
.
find
(
'b'
),
y
.
find
(
'b'
));
...
@@ -126,7 +126,7 @@ CAF_TEST(find) {
...
@@ -126,7 +126,7 @@ CAF_TEST(find) {
CAF_TEST
(
rfind
)
{
CAF_TEST
(
rfind
)
{
// Check whether string_view behaves exactly like std::string.
// Check whether string_view behaves exactly like std::string.
string_view
x
=
"abccba"
;
auto
x
=
"abccba"
_sv
;
std
::
string
y
=
"abccba"
;
std
::
string
y
=
"abccba"
;
CAF_CHECK_EQUAL
(
x
.
rfind
(
'a'
),
y
.
rfind
(
'a'
));
CAF_CHECK_EQUAL
(
x
.
rfind
(
'a'
),
y
.
rfind
(
'a'
));
CAF_CHECK_EQUAL
(
x
.
rfind
(
'b'
),
y
.
rfind
(
'b'
));
CAF_CHECK_EQUAL
(
x
.
rfind
(
'b'
),
y
.
rfind
(
'b'
));
...
@@ -143,7 +143,7 @@ CAF_TEST(rfind) {
...
@@ -143,7 +143,7 @@ CAF_TEST(rfind) {
CAF_TEST
(
find_first_of
)
{
CAF_TEST
(
find_first_of
)
{
// Check whether string_view behaves exactly like std::string.
// Check whether string_view behaves exactly like std::string.
string_view
x
=
"abcdef"
;
auto
x
=
"abcdef"
_sv
;
std
::
string
y
=
"abcdef"
;
std
::
string
y
=
"abcdef"
;
CAF_CHECK_EQUAL
(
x
.
find_first_of
(
'a'
),
y
.
find_first_of
(
'a'
));
CAF_CHECK_EQUAL
(
x
.
find_first_of
(
'a'
),
y
.
find_first_of
(
'a'
));
CAF_CHECK_EQUAL
(
x
.
find_first_of
(
'b'
),
y
.
find_first_of
(
'b'
));
CAF_CHECK_EQUAL
(
x
.
find_first_of
(
'b'
),
y
.
find_first_of
(
'b'
));
...
@@ -160,7 +160,7 @@ CAF_TEST(find_first_of) {
...
@@ -160,7 +160,7 @@ CAF_TEST(find_first_of) {
CAF_TEST
(
find_last_of
)
{
CAF_TEST
(
find_last_of
)
{
// Check whether string_view behaves exactly like std::string.
// Check whether string_view behaves exactly like std::string.
string_view
x
=
"abcdef"
;
auto
x
=
"abcdef"
_sv
;
std
::
string
y
=
"abcdef"
;
std
::
string
y
=
"abcdef"
;
CAF_CHECK_EQUAL
(
x
.
find_last_of
(
'a'
),
y
.
find_last_of
(
'a'
));
CAF_CHECK_EQUAL
(
x
.
find_last_of
(
'a'
),
y
.
find_last_of
(
'a'
));
CAF_CHECK_EQUAL
(
x
.
find_last_of
(
'b'
),
y
.
find_last_of
(
'b'
));
CAF_CHECK_EQUAL
(
x
.
find_last_of
(
'b'
),
y
.
find_last_of
(
'b'
));
...
@@ -177,7 +177,7 @@ CAF_TEST(find_last_of) {
...
@@ -177,7 +177,7 @@ CAF_TEST(find_last_of) {
CAF_TEST
(
find_first_not_of
)
{
CAF_TEST
(
find_first_not_of
)
{
// Check whether string_view behaves exactly like std::string.
// Check whether string_view behaves exactly like std::string.
string_view
x
=
"abcdef"
;
auto
x
=
"abcdef"
_sv
;
std
::
string
y
=
"abcdef"
;
std
::
string
y
=
"abcdef"
;
CAF_CHECK_EQUAL
(
x
.
find_first_not_of
(
'a'
),
y
.
find_first_not_of
(
'a'
));
CAF_CHECK_EQUAL
(
x
.
find_first_not_of
(
'a'
),
y
.
find_first_not_of
(
'a'
));
CAF_CHECK_EQUAL
(
x
.
find_first_not_of
(
'b'
),
y
.
find_first_not_of
(
'b'
));
CAF_CHECK_EQUAL
(
x
.
find_first_not_of
(
'b'
),
y
.
find_first_not_of
(
'b'
));
...
@@ -197,7 +197,7 @@ CAF_TEST(find_first_not_of) {
...
@@ -197,7 +197,7 @@ CAF_TEST(find_first_not_of) {
CAF_TEST
(
find_last_not_of
)
{
CAF_TEST
(
find_last_not_of
)
{
// Check whether string_view behaves exactly like std::string.
// Check whether string_view behaves exactly like std::string.
string_view
x
=
"abcdef"
;
auto
x
=
"abcdef"
_sv
;
std
::
string
y
=
"abcdef"
;
std
::
string
y
=
"abcdef"
;
CAF_CHECK_EQUAL
(
x
.
find_last_not_of
(
'a'
),
y
.
find_last_not_of
(
'a'
));
CAF_CHECK_EQUAL
(
x
.
find_last_not_of
(
'a'
),
y
.
find_last_not_of
(
'a'
));
CAF_CHECK_EQUAL
(
x
.
find_last_not_of
(
'b'
),
y
.
find_last_not_of
(
'b'
));
CAF_CHECK_EQUAL
(
x
.
find_last_not_of
(
'b'
),
y
.
find_last_not_of
(
'b'
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment