continue;\r
}\r
if ((stricmp (argv[0], "--hash") == 0)) {\r
+ if (EnableHash == TRUE) {\r
+ //\r
+ // --hash already given in the option, ignore this one\r
+ //\r
+ argc --;\r
+ argv ++;\r
+ continue;\r
+ }\r
EnableHash = TRUE;\r
OpenSslCommand = "openssl";\r
OpenSslEnv = getenv("OPENSSL_PATH");\r
CHAR8 *ExtractionTool;\r
CHAR8 *ToolInputFile;\r
CHAR8 *ToolOutputFile;\r
- CHAR8 *SystemCommandFormatString;\r
CHAR8 *SystemCommand;\r
EFI_GUID *EfiGuid;\r
UINT16 DataOffset;\r
SectionLength - SectionHeaderLen\r
);\r
\r
- SystemCommandFormatString = "%s sha1 -out %s %s";\r
SystemCommand = malloc (\r
- strlen (SystemCommandFormatString) +\r
+ strlen (OPENSSL_COMMAND_FORMAT_STRING) +\r
strlen (OpenSslPath) +\r
strlen (ToolInputFileName) +\r
strlen (ToolOutputFileName) +\r
}\r
sprintf (\r
SystemCommand,\r
- SystemCommandFormatString,\r
+ OPENSSL_COMMAND_FORMAT_STRING,\r
OpenSslPath,\r
ToolOutputFileName,\r
ToolInputFileName\r
}\r
\r
ScratchBuffer = malloc (ScratchSize);\r
+ if (ScratchBuffer == NULL) {\r
+ Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
UncompressedBuffer = malloc (UncompressedLength);\r
- if ((ScratchBuffer == NULL) || (UncompressedBuffer == NULL)) {\r
+ if (UncompressedBuffer == NULL) {\r
+ free (ScratchBuffer);\r
+ Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");\r
return EFI_OUT_OF_RESOURCES;\r
}\r
Status = DecompressFunction (\r
//\r
// Construction 'system' command string\r
//\r
- SystemCommandFormatString = "%s -d -o %s %s";\r
SystemCommand = malloc (\r
- strlen (SystemCommandFormatString) +\r
+ strlen (EXTRACT_COMMAND_FORMAT_STRING) +\r
strlen (ExtractionTool) +\r
strlen (ToolInputFile) +\r
strlen (ToolOutputFile) +\r
}\r
sprintf (\r
SystemCommand,\r
- SystemCommandFormatString,\r
+ EXTRACT_COMMAND_FORMAT_STRING,\r
ExtractionTool,\r
ToolOutputFile,\r
ToolInputFile\r
{\r
FILE *Fptr;\r
CHAR8 Line[MAX_LINE_LEN];\r
+ CHAR8 *FormatString;\r
+ INTN FormatLength;\r
GUID_TO_BASENAME *GPtr;\r
\r
if ((Fptr = fopen (LongFilePath (FileName), "r")) == NULL) {\r
return EFI_DEVICE_ERROR;\r
}\r
\r
+ //\r
+ // Generate the format string for fscanf\r
+ //\r
+ FormatLength = snprintf (\r
+ NULL,\r
+ 0,\r
+ "%%%us %%%us",\r
+ (unsigned) sizeof (GPtr->Guid) - 1,\r
+ (unsigned) sizeof (GPtr->BaseName) - 1\r
+ ) + 1;\r
+\r
+ FormatString = (CHAR8 *) malloc (FormatLength);\r
+ if (FormatString == NULL) {\r
+ fclose (Fptr);\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+\r
+ snprintf (\r
+ FormatString,\r
+ FormatLength,\r
+ "%%%us %%%us",\r
+ (unsigned) sizeof (GPtr->Guid) - 1,\r
+ (unsigned) sizeof (GPtr->BaseName) - 1\r
+ );\r
+\r
while (fgets (Line, sizeof (Line), Fptr) != NULL) {\r
//\r
// Allocate space for another guid/basename element\r
//\r
GPtr = malloc (sizeof (GUID_TO_BASENAME));\r
if (GPtr == NULL) {\r
+ free (FormatString);\r
+ fclose (Fptr);\r
return EFI_OUT_OF_RESOURCES;\r
}\r
\r
memset ((char *) GPtr, 0, sizeof (GUID_TO_BASENAME));\r
- if (sscanf (Line, "%s %s", GPtr->Guid, GPtr->BaseName) == 2) {\r
+ if (sscanf (Line, FormatString, GPtr->Guid, GPtr->BaseName) == 2) {\r
GPtr->Next = mGuidBaseNameList;\r
mGuidBaseNameList = GPtr;\r
} else {\r
}\r
}\r
\r
+ free (FormatString);\r
fclose (Fptr);\r
return EFI_SUCCESS;\r
}\r