mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Merge #6206
6206: Remove possible overflow in str_comp_filenames (fixes #6204) r=def- a=Chairn ## Checklist - [ ] Tested the change ingame - [ ] Provided screenshots if it is a visual change - [ ] Tested in combination with possibly related configuration options - [x] Written a unit test (especially base/) or added coverage to integration test - [x] Considered possible null pointers and out of bounds array indexing - [x] Changed no physics that affect existing maps - [x] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional) Co-authored-by: Chairn <chairn.nq@hotmail.fr>
This commit is contained in:
commit
beae6b8a6b
|
@ -2831,10 +2831,8 @@ int str_comp_filenames(const char *a, const char *b)
|
|||
{
|
||||
if(*a >= '0' && *a <= '9' && *b >= '0' && *b <= '9')
|
||||
{
|
||||
result = 0;
|
||||
do
|
||||
{
|
||||
if(!result)
|
||||
result = *a - *b;
|
||||
++a;
|
||||
++b;
|
||||
|
@ -2844,7 +2842,7 @@ int str_comp_filenames(const char *a, const char *b)
|
|||
return 1;
|
||||
else if(*b >= '0' && *b <= '9')
|
||||
return -1;
|
||||
else if(result)
|
||||
else if(!(!result && *a && *b))
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -820,6 +820,13 @@ TEST(Str, CompFilename)
|
|||
EXPECT_GT(str_comp_filenames("b", "A"), 0);
|
||||
EXPECT_LT(str_comp_filenames("a", "B"), 0);
|
||||
EXPECT_GT(str_comp_filenames("B", "a"), 0);
|
||||
EXPECT_EQ(str_comp_filenames("1A", "1a"), 0);
|
||||
EXPECT_LT(str_comp_filenames("1a", "1B"), 0);
|
||||
EXPECT_GT(str_comp_filenames("1B", "1a"), 0);
|
||||
EXPECT_LT(str_comp_filenames("1a", "1b"), 0);
|
||||
EXPECT_GT(str_comp_filenames("1b", "1a"), 0);
|
||||
EXPECT_GT(str_comp_filenames("12a", "1B"), 0);
|
||||
EXPECT_LT(str_comp_filenames("1B", "12a"), 0);
|
||||
EXPECT_LT(str_comp_filenames("abc", "abcd"), 0);
|
||||
EXPECT_GT(str_comp_filenames("abcd", "abc"), 0);
|
||||
EXPECT_LT(str_comp_filenames("abc2", "abcd1"), 0);
|
||||
|
@ -829,8 +836,17 @@ TEST(Str, CompFilename)
|
|||
EXPECT_EQ(str_comp_filenames("file0", "file0"), 0);
|
||||
EXPECT_LT(str_comp_filenames("file0", "file1"), 0);
|
||||
EXPECT_GT(str_comp_filenames("file1", "file0"), 0);
|
||||
EXPECT_LT(str_comp_filenames("file1", "file09"), 0);
|
||||
EXPECT_GT(str_comp_filenames("file09", "file1"), 0);
|
||||
EXPECT_LT(str_comp_filenames("file1", "file009"), 0);
|
||||
EXPECT_GT(str_comp_filenames("file009", "file1"), 0);
|
||||
EXPECT_LT(str_comp_filenames("file13", "file37"), 0);
|
||||
EXPECT_GT(str_comp_filenames("file37", "file13"), 0);
|
||||
EXPECT_LT(str_comp_filenames("file1.ext", "file09.ext"), 0);
|
||||
EXPECT_GT(str_comp_filenames("file09.ext", "file1.ext"), 0);
|
||||
EXPECT_LT(str_comp_filenames("file1.ext", "file009.ext"), 0);
|
||||
EXPECT_GT(str_comp_filenames("file009.ext", "file1.ext"), 0);
|
||||
EXPECT_EQ(str_comp_filenames("file0.ext", "file0.ext"), 0);
|
||||
EXPECT_LT(str_comp_filenames("file13.ext", "file37.ext"), 0);
|
||||
EXPECT_GT(str_comp_filenames("file37.ext", "file13.ext"), 0);
|
||||
EXPECT_LT(str_comp_filenames("FILE13.EXT", "file37.ext"), 0);
|
||||
|
|
Loading…
Reference in a new issue