1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/nss/lib/libpkix/pkix/util/pkix_errpaths.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,103 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 +/* 1.8 + * pkix_errpaths.c 1.9 + * 1.10 + * Error Handling Helper Functions 1.11 + * 1.12 + */ 1.13 + 1.14 +#define PKIX_STDVARS_POINTER 1.15 +#include "pkix_error.h" 1.16 + 1.17 +const PKIX_StdVars zeroStdVars; 1.18 + 1.19 +PKIX_Error* 1.20 +PKIX_DoThrow(PKIX_StdVars * stdVars, PKIX_ERRORCLASS errClass, 1.21 + PKIX_ERRORCODE errCode, PKIX_ERRORCLASS overrideClass, 1.22 + void *plContext) 1.23 +{ 1.24 + if (!pkixErrorReceived && !pkixErrorResult && pkixErrorList) { 1.25 + pkixTempResult = PKIX_List_GetItem(pkixErrorList, 0, 1.26 + (PKIX_PL_Object**)&pkixReturnResult, 1.27 + plContext); 1.28 + } else { 1.29 + pkixTempResult = (PKIX_Error*)pkix_Throw(errClass, myFuncName, errCode, 1.30 + overrideClass, pkixErrorResult, 1.31 + &pkixReturnResult, plContext); 1.32 + } 1.33 + if (pkixReturnResult) { 1.34 + if (pkixErrorResult != PKIX_ALLOC_ERROR()) { 1.35 + PKIX_DECREF(pkixErrorResult); 1.36 + } 1.37 + pkixTempResult = pkixReturnResult; 1.38 + } else if (pkixErrorResult) { 1.39 + if (pkixTempResult != PKIX_ALLOC_ERROR()) { 1.40 + PKIX_DECREF(pkixTempResult); 1.41 + } 1.42 + pkixTempResult = pkixErrorResult; 1.43 + } 1.44 + if (pkixErrorList) { 1.45 + PKIX_PL_Object_DecRef((PKIX_PL_Object*)pkixErrorList, plContext); 1.46 + pkixErrorList = NULL; 1.47 + } 1.48 + return pkixTempResult; 1.49 +} 1.50 + 1.51 +PKIX_Error * 1.52 +PKIX_DoReturn(PKIX_StdVars * stdVars, PKIX_ERRORCLASS errClass, 1.53 + PKIX_Boolean doLogger, void *plContext) 1.54 +{ 1.55 + PKIX_OBJECT_UNLOCK(lockedObject); 1.56 + if (pkixErrorReceived || pkixErrorResult || pkixErrorList) 1.57 + return PKIX_DoThrow(stdVars, errClass, pkixErrorCode, pkixErrorClass, 1.58 + plContext); 1.59 + /* PKIX_DEBUG_EXIT(type); */ 1.60 + if (doLogger) 1.61 + _PKIX_DEBUG_TRACE(pkixLoggersDebugTrace, "<<<", PKIX_LOGGER_LEVEL_TRACE); 1.62 + return NULL; 1.63 +} 1.64 + 1.65 +/* PKIX_DoAddError - creates the list of received error if it does not exist 1.66 + * yet and adds newly received error into the list. */ 1.67 +void 1.68 +PKIX_DoAddError(PKIX_StdVars *stdVars, PKIX_Error *error, void * plContext) 1.69 +{ 1.70 + PKIX_List *localList = NULL; 1.71 + PKIX_Error *localError = NULL; 1.72 + PKIX_Boolean listCreated = PKIX_FALSE; 1.73 + 1.74 + if (!pkixErrorList) { 1.75 + localError = PKIX_List_Create(&localList, plContext); 1.76 + if (localError) 1.77 + goto cleanup; 1.78 + listCreated = PKIX_TRUE; 1.79 + } else { 1.80 + localList = pkixErrorList; 1.81 + } 1.82 + 1.83 + localError = PKIX_List_AppendItem(localList, (PKIX_PL_Object*)error, 1.84 + plContext); 1.85 + PORT_Assert (localError == NULL); 1.86 + if (localError != NULL) { 1.87 + if (listCreated) { 1.88 + /* ignore the error code of DecRef function */ 1.89 + PKIX_PL_Object_DecRef((PKIX_PL_Object*)localList, plContext); 1.90 + localList = NULL; 1.91 + } 1.92 + } else { 1.93 + pkixErrorList = localList; 1.94 + } 1.95 + 1.96 +cleanup: 1.97 + 1.98 + if (localError && localError != PKIX_ALLOC_ERROR()) { 1.99 + PKIX_PL_Object_DecRef((PKIX_PL_Object*)localError, plContext); 1.100 + } 1.101 + 1.102 + if (error && error != PKIX_ALLOC_ERROR()) { 1.103 + PKIX_PL_Object_DecRef((PKIX_PL_Object*)error, plContext); 1.104 + } 1.105 +} 1.106 +