From b22d9f5c9c1baba53d64bfec90366a1e06abe56c Mon Sep 17 00:00:00 2001 From: m3g4d1v3r <99227953+m3g4d1v3r@users.noreply.github.com> Date: Sat, 9 Nov 2024 15:00:42 +0200 Subject: [PATCH] Add checking and testing for invalid privals in stumpless-get-priority-string --- src/prival.c | 4 ++++ test/function/prival.cpp | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/prival.c b/src/prival.c index 224bd0042..0199efde5 100644 --- a/src/prival.c +++ b/src/prival.c @@ -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 ) ); diff --git a/test/function/prival.cpp b/test/function/prival.cpp index a645bf241..eea7a77ef 100644 --- a/test/function/prival.cpp +++ b/test/function/prival.cpp @@ -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 ); + } }