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 5a72426
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/prival.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ stumpless_get_priority_string( int prival ) {
size_t priority_string_size;
char* priority_string;

if (facility_is_invalid(get_facility(prival)))
return NULL;
if (severity_is_invalid(get_severity(prival)))
return NULL;

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

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

free( ( void * ) result );
}

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

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

free( ( void * ) result );
}
}

0 comments on commit 5a72426

Please sign in to comment.