diff options
Diffstat (limited to 'src/errors.c')
-rw-r--r-- | src/errors.c | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/src/errors.c b/src/errors.c index a4519270..179caa73 100644 --- a/src/errors.c +++ b/src/errors.c @@ -1,19 +1,26 @@ -/** +/* * XML Security Library (http://www.aleksey.com/xmlsec). * - * Error codes and error reporting functions. * * This is free software; see Copyright file in the source * distribution for preciese wording. * * Copyright (C) 2002-2016 Aleksey Sanin <aleksey@aleksey.com>. All Rights Reserved. */ +/** + * SECTION:errors + * @Short_description: Error reporting and logging functions. + * @Stability: Stable + * + */ + #include "globals.h" #include <stdlib.h> #include <stdio.h> #include <stdarg.h> #include <time.h> +#include <string.h> #include <libxml/tree.h> @@ -22,8 +29,12 @@ #include <xmlsec/private.h> #include <xmlsec/errors.h> +/* Must be bigger than fatal_error */ #define XMLSEC_ERRORS_BUFFER_SIZE 1024 +/* Must fit into xmlChar[XMLSEC_ERRORS_BUFFER_SIZE] */ +static const xmlChar fatal_error[] = "Can not format error message"; + typedef struct _xmlSecErrorDescription xmlSecErrorDescription, *xmlSecErrorDescriptionPtr; struct _xmlSecErrorDescription { int errorCode; @@ -40,6 +51,7 @@ static xmlSecErrorDescription xmlSecErrorsTable[XMLSEC_ERRORS_MAX_NUMBER + 1] = { XMLSEC_ERRORS_R_IO_FAILED, "io function failed" }, { XMLSEC_ERRORS_R_DISABLED, "feature is disabled" }, { XMLSEC_ERRORS_R_NOT_IMPLEMENTED, "feature is not implemented" }, + { XMLSEC_ERRORS_R_INVALID_CONFIG, "invalid configuration" }, { XMLSEC_ERRORS_R_INVALID_SIZE, "invalid size" }, { XMLSEC_ERRORS_R_INVALID_DATA, "invalid data" }, { XMLSEC_ERRORS_R_INVALID_RESULT, "invalid result" }, @@ -48,6 +60,7 @@ static xmlSecErrorDescription xmlSecErrorsTable[XMLSEC_ERRORS_MAX_NUMBER + 1] = { XMLSEC_ERRORS_R_INVALID_STATUS, "invalid status" }, { XMLSEC_ERRORS_R_INVALID_FORMAT, "invalid format" }, { XMLSEC_ERRORS_R_DATA_NOT_MATCH, "data do not match" }, + { XMLSEC_ERRORS_R_INVALID_VERSION, "invalid version" }, { XMLSEC_ERRORS_R_INVALID_NODE, "invalid node" }, { XMLSEC_ERRORS_R_INVALID_NODE_CONTENT, "invalid node content" }, { XMLSEC_ERRORS_R_INVALID_NODE_ATTRIBUTE, "invalid node attribute" }, @@ -74,7 +87,7 @@ static xmlSecErrorDescription xmlSecErrorsTable[XMLSEC_ERRORS_MAX_NUMBER + 1] = { XMLSEC_ERRORS_R_CERT_REVOKED, "certificate is revoked" }, { XMLSEC_ERRORS_R_CERT_ISSUER_FAILED, "certificate issuer check failed" }, { XMLSEC_ERRORS_R_CERT_NOT_YET_VALID, "certificate is not yet valid" }, - { XMLSEC_ERRORS_R_CERT_HAS_EXPIRED, "certificate has expirred" }, + { XMLSEC_ERRORS_R_CERT_HAS_EXPIRED, "certificate has expired" }, { XMLSEC_ERRORS_R_DSIG_NO_REFERENCES, "Reference nodes are not found" }, { XMLSEC_ERRORS_R_DSIG_INVALID_REFERENCE, "Reference verification failed" }, { XMLSEC_ERRORS_R_ASSERTION, "assertion" }, @@ -82,7 +95,7 @@ static xmlSecErrorDescription xmlSecErrorsTable[XMLSEC_ERRORS_MAX_NUMBER + 1] = }; static xmlSecErrorsCallback xmlSecErrorsClbk = xmlSecErrorsDefaultCallback; -static int xmlSecPrintErrorMessages = 1; /* whether the error messages will be printed immidiatelly */ +static int xmlSecPrintErrorMessages = 1; /* whether the error messages will be printed immediately */ /** * xmlSecErrorsInit: @@ -208,9 +221,9 @@ xmlSecErrorsGetMsg(xmlSecSize pos) { * xmlSecError: * @file: the error location filename (__FILE__). * @line: the error location line number (__LINE__). - * @func: the error location function (__FUNCTIION__). - * @errorObject: the error specific error object - * @errorSubject: the error specific error subject. + * @func: the error location function (__FUNCTION__). + * @errorObject: the error specific error object (e.g. transform, key data, etc). + * @errorSubject: the error specific error subject (e.g. failed function name). * @reason: the error code. * @msg: the error message in printf format. * @...: the parameters for the @msg. @@ -223,15 +236,20 @@ void xmlSecError(const char* file, int line, const char* func, const char* errorObject, const char* errorSubject, int reason, const char* msg, ...) { - if(xmlSecErrorsClbk != NULL) { xmlChar error_msg[XMLSEC_ERRORS_BUFFER_SIZE]; + int ret; if(msg != NULL) { va_list va; + va_start(va, msg); - xmlSecStrVPrintf(error_msg, sizeof(error_msg), msg, va); - error_msg[sizeof(error_msg) - 1] = '\0'; + ret = xmlStrVPrintf(error_msg, sizeof(error_msg), msg, va); + if(ret < 0) { + /* Can't really report an error from an error callback */ + memcpy(error_msg, fatal_error, sizeof(fatal_error)); + } + error_msg[sizeof(error_msg) - 1] = '\0'; /* just in case */ va_end(va); } else { error_msg[0] = '\0'; |