Skip to content

Commit

Permalink
Add checking and testing for invalid privals in stumpless-get-priorit…
Browse files Browse the repository at this point in the history
…y-string
  • Loading branch information
m3g4d1v3r committed Nov 9, 2024
1 parent c0fb2e4 commit b22d9f5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/prival.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ stumpless_get_priority_string( int prival ) {
size_t priority_string_size;
char* priority_string;

if ((prival & 0xff) != prival) {
return NULL;
}

facility = stumpless_get_facility_string( get_facility( prival ) );
severity = stumpless_get_severity_string( get_severity( prival ) );

Expand Down
17 changes: 17 additions & 0 deletions test/function/prival.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,21 @@ namespace {

free( ( void * ) result );
}

TEST(GetPriorityString, InvalidPrivals) {
int prival;
const char *result;

prival = -1;
result = stumpless_get_priority_string( prival );
EXPECT_STREQ( result, NULL );

free( ( void * ) result );

prival = 0x100;
result = stumpless_get_priority_string( prival );
EXPECT_STREQ( result, NULL );

free( ( void * ) result );
}
}

0 comments on commit b22d9f5

Please sign in to comment.