\r
EFI_REGULAR_EXPRESSION_PROTOCOL Implementation\r
\r
- Copyright (c) 2015, Hewlett Packard Enterprise Development, L.P.<BR>\r
+ (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>\r
\r
This program and the accompanying materials are licensed and made available\r
under the terms and conditions of the BSD License that accompanies this\r
OnigRegion *Region;\r
INT32 OnigResult;\r
OnigErrorInfo ErrorInfo;\r
- CHAR8 ErrorMessage[ONIG_MAX_ERROR_MESSAGE_LEN];\r
+ OnigUChar ErrorMessage[ONIG_MAX_ERROR_MESSAGE_LEN];\r
UINT32 Index;\r
OnigUChar *Start;\r
+ EFI_STATUS Status;\r
+\r
+\r
+ Status = EFI_SUCCESS;\r
\r
//\r
// Detemine the internal syntax type\r
OnigSyntax = ONIG_SYNTAX_PERL;\r
} else {\r
DEBUG ((DEBUG_ERROR, "Unsupported regex syntax - using default\n"));\r
- ASSERT (FALSE);\r
+ return EFI_UNSUPPORTED;\r
}\r
\r
//\r
//\r
Start = (OnigUChar*)String;\r
Region = onig_region_new ();\r
+ if (Region == NULL) {\r
+ onig_free (OnigRegex);\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
OnigResult = onig_search (\r
OnigRegex,\r
Start,\r
Region,\r
ONIG_OPTION_NONE\r
);\r
+\r
if (OnigResult >= 0) {\r
*Result = TRUE;\r
} else {\r
if (OnigResult != ONIG_MISMATCH) {\r
onig_error_code_to_str (ErrorMessage, OnigResult);\r
DEBUG ((DEBUG_ERROR, "Regex match failed: %a\n", ErrorMessage));\r
+ onig_region_free (Region, 1);\r
+ onig_free (OnigRegex);\r
+ return EFI_DEVICE_ERROR;\r
}\r
}\r
\r
//\r
if (*Result && Captures != NULL) {\r
*CapturesCount = Region->num_regs;\r
- *Captures = AllocatePool (*CapturesCount * sizeof(**Captures));\r
+ *Captures = AllocateZeroPool (*CapturesCount * sizeof(**Captures));\r
if (*Captures != NULL) {\r
for (Index = 0; Index < *CapturesCount; ++Index) {\r
//\r
// Region beg/end values represent bytes, not characters\r
//\r
- (*Captures)[Index].CapturePtr = (CHAR16*)((UINTN)String + Region->beg[Index]);\r
(*Captures)[Index].Length = (Region->end[Index] - Region->beg[Index]) / sizeof(CHAR16);\r
+ (*Captures)[Index].CapturePtr = AllocateCopyPool (\r
+ ((*Captures)[Index].Length) * sizeof (CHAR16),\r
+ (CHAR16*)((UINTN)String + Region->beg[Index])\r
+ );\r
+ if ((*Captures)[Index].CapturePtr == NULL) {\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ break;\r
+ }\r
+ }\r
+\r
+ if (EFI_ERROR (Status)) {\r
+ for (Index = 0; Index < *CapturesCount; ++Index) {\r
+ if ((*Captures)[Index].CapturePtr != NULL) {\r
+ FreePool ((CHAR16*)(*Captures)[Index].CapturePtr);\r
+ }\r
+ }\r
+ FreePool (*Captures);\r
}\r
}\r
}\r
onig_region_free (Region, 1);\r
onig_free (OnigRegex);\r
\r
- return EFI_SUCCESS;\r
+ return Status;\r
}\r
\r
/**\r