Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
VideoLAN
medialibrary
Commits
eead6f2c
Commit
eead6f2c
authored
Feb 14, 2018
by
Hugo Beauzée-Luyssen
Browse files
utils: File: Fix potential overflow
parent
78779952
Changes
2
Show whitespace changes
Inline
Side-by-side
src/utils/Filename.cpp
View file @
eead6f2c
...
@@ -149,7 +149,7 @@ std::string firstFolder( const std::string& path )
...
@@ -149,7 +149,7 @@ std::string firstFolder( const std::string& path )
std
::
string
removePath
(
const
std
::
string
&
fullPath
,
const
std
::
string
&
toRemove
)
std
::
string
removePath
(
const
std
::
string
&
fullPath
,
const
std
::
string
&
toRemove
)
{
{
if
(
toRemove
.
length
()
==
0
)
if
(
toRemove
.
length
()
==
0
||
toRemove
.
length
()
>
fullPath
.
length
()
)
return
fullPath
;
return
fullPath
;
auto
pos
=
fullPath
.
find
(
toRemove
);
auto
pos
=
fullPath
.
find
(
toRemove
);
if
(
pos
==
std
::
string
::
npos
)
if
(
pos
==
std
::
string
::
npos
)
...
...
test/unittest/FsUtilsTests.cpp
View file @
eead6f2c
...
@@ -94,6 +94,7 @@ TEST( FsUtils, removePath )
...
@@ -94,6 +94,7 @@ TEST( FsUtils, removePath )
ASSERT_EQ
(
""
,
utils
::
file
::
removePath
(
"bar/"
,
"bar"
)
);
ASSERT_EQ
(
""
,
utils
::
file
::
removePath
(
"bar/"
,
"bar"
)
);
ASSERT_EQ
(
""
,
utils
::
file
::
removePath
(
"/f00/"
,
"/f00/"
)
);
ASSERT_EQ
(
""
,
utils
::
file
::
removePath
(
"/f00/"
,
"/f00/"
)
);
ASSERT_EQ
(
"/f00"
,
utils
::
file
::
removePath
(
"/f00"
,
"/path/not/found"
)
);
ASSERT_EQ
(
"/f00"
,
utils
::
file
::
removePath
(
"/f00"
,
"/path/not/found"
)
);
ASSERT_EQ
(
"/f00"
,
utils
::
file
::
removePath
(
"/f00"
,
"/loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongstring/"
)
);
}
}
TEST
(
FsUtils
,
parentFolder
)
TEST
(
FsUtils
,
parentFolder
)
...
...
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