From 235033d63380b7bf27aaa2e710afabfe996f91ae Mon Sep 17 00:00:00 2001 From: Andrew Kesterson Date: Sun, 24 May 2026 19:14:35 -0400 Subject: [PATCH] VALID() wasn't properly handling NULL returns, leading to false positives --- include/akerror.tmpl.h | 2 +- src/error.c | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/akerror.tmpl.h b/include/akerror.tmpl.h index 51d48c7..64a3d2b 100644 --- a/include/akerror.tmpl.h +++ b/include/akerror.tmpl.h @@ -185,7 +185,7 @@ void akerr_init_errno(void); #define VALID(__err_context, __stmt) \ __stmt; \ - if ( akerr_valid_error_address(__err_context) == 1 ) { \ + if ( akerr_valid_error_address(__err_context) == 0 ) { \ FAIL(__err_context, AKERR_BEHAVIOR, "Received (akerr_Error *) from an invalid memory region. (Did the method finish without calling SUCCEED_RETURN?)"); \ } diff --git a/src/error.c b/src/error.c index c853bda..e027053 100644 --- a/src/error.c +++ b/src/error.c @@ -17,7 +17,11 @@ akerr_ErrorContext AKERR_ARRAY_ERROR[AKERR_MAX_ARRAY_ERROR]; int akerr_valid_error_address(akerr_ErrorContext *ptr) { // Is this within the memory region occupied by AKERR_ARRAY_ERROR? - return ((ptr >= &AKERR_ARRAY_ERROR[0]) && (ptr <= &AKERR_ARRAY_ERROR[AKERR_MAX_ARRAY_ERROR-1])); + if ( ptr == NULL ) { + return 1; + } + return ((ptr >= &AKERR_ARRAY_ERROR[0]) && + (ptr <= &AKERR_ARRAY_ERROR[AKERR_MAX_ARRAY_ERROR-1])); } void akerr_default_logger(const char *fmt, ...)