Skip to content

Commit

Permalink
fix severity from string functions
Browse files Browse the repository at this point in the history
Strings that were a case-insensitive prefix of a valid severity string
were incorrectly accepted due to an incomplete case-insensitive comparison
implementation. This change corrects this and adds tests to prevent
regression.
  • Loading branch information
lecapitainenemo authored Oct 2, 2024
1 parent 72f40f9 commit 1bd3333
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/strhelper.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,11 @@ strncasecmp_custom( const char *s1, const char *s2, size_t n ) {
if (n != 0) {
do {
if (tolower(*s1) != tolower(*s2++))
return tolower(*s1) - tolower(*--s2);
return tolower(*--s2) - tolower(*s1);
if (*s1++ == '\0')
break;
} while (--n != 0);
if(*s2 != '\0') return tolower(*s2) - tolower(*s1);
}
return 0;
}
}
24 changes: 24 additions & 0 deletions test/function/severity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,28 @@ namespace {
EXPECT_EQ( result, -1 );
}

TEST( GetSeverityEnumFromBuffer, IncompleteSeverity ) {
enum stumpless_severity result = stumpless_get_severity_enum( "war" );
EXPECT_EQ( result, -1 );

result = stumpless_get_severity_enum( "not" );
EXPECT_EQ( result, -1 );
}


TEST( GetSeverityEnumFromBuffer, OverextendedSeverity ) {
enum stumpless_severity result = stumpless_get_severity_enum( "warnings are neat" );
EXPECT_EQ( result, -1 );

result = stumpless_get_severity_enum( "notices are bad" );
EXPECT_EQ( result, -1 );

result = stumpless_get_severity_enum( "panic you should not" );
EXPECT_EQ( result, -1 );

}




}

0 comments on commit 1bd3333

Please sign in to comment.