X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=BaseTools%2FSource%2FC%2FVolInfo%2FVolInfo.c;h=46c72123c87538f8457b4d8fd835c4a9a70edef1;hb=aeadb1c453174d543ad95d2a601e229506b2679e;hp=5da658298e17aca8af7150ec0555d618e31707cd;hpb=ed9ff2688a6329b0eed8bc14d287e7a644975a6c;p=mirror_edk2.git diff --git a/BaseTools/Source/C/VolInfo/VolInfo.c b/BaseTools/Source/C/VolInfo/VolInfo.c index 5da658298e..46c72123c8 100644 --- a/BaseTools/Source/C/VolInfo/VolInfo.c +++ b/BaseTools/Source/C/VolInfo/VolInfo.c @@ -258,6 +258,14 @@ Returns: continue; } if ((stricmp (argv[0], "--hash") == 0)) { + if (EnableHash == TRUE) { + // + // --hash already given in the option, ignore this one + // + argc --; + argv ++; + continue; + } EnableHash = TRUE; OpenSslCommand = "openssl"; OpenSslEnv = getenv("OPENSSL_PATH"); @@ -1591,7 +1599,6 @@ Returns: CHAR8 *ExtractionTool; CHAR8 *ToolInputFile; CHAR8 *ToolOutputFile; - CHAR8 *SystemCommandFormatString; CHAR8 *SystemCommand; EFI_GUID *EfiGuid; UINT16 DataOffset; @@ -1651,9 +1658,8 @@ Returns: SectionLength - SectionHeaderLen ); - SystemCommandFormatString = "%s sha1 -out %s %s"; SystemCommand = malloc ( - strlen (SystemCommandFormatString) + + strlen (OPENSSL_COMMAND_FORMAT_STRING) + strlen (OpenSslPath) + strlen (ToolInputFileName) + strlen (ToolOutputFileName) + @@ -1665,7 +1671,7 @@ Returns: } sprintf ( SystemCommand, - SystemCommandFormatString, + OPENSSL_COMMAND_FORMAT_STRING, OpenSslPath, ToolOutputFileName, ToolInputFileName @@ -1784,8 +1790,14 @@ Returns: } ScratchBuffer = malloc (ScratchSize); + if (ScratchBuffer == NULL) { + Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!"); + return EFI_OUT_OF_RESOURCES; + } UncompressedBuffer = malloc (UncompressedLength); - if ((ScratchBuffer == NULL) || (UncompressedBuffer == NULL)) { + if (UncompressedBuffer == NULL) { + free (ScratchBuffer); + Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!"); return EFI_OUT_OF_RESOURCES; } Status = DecompressFunction ( @@ -1877,9 +1889,8 @@ Returns: // // Construction 'system' command string // - SystemCommandFormatString = "%s -d -o %s %s"; SystemCommand = malloc ( - strlen (SystemCommandFormatString) + + strlen (EXTRACT_COMMAND_FORMAT_STRING) + strlen (ExtractionTool) + strlen (ToolInputFile) + strlen (ToolOutputFile) + @@ -1895,7 +1906,7 @@ Returns: } sprintf ( SystemCommand, - SystemCommandFormatString, + EXTRACT_COMMAND_FORMAT_STRING, ExtractionTool, ToolOutputFile, ToolInputFile @@ -2164,6 +2175,8 @@ Returns: { FILE *Fptr; CHAR8 Line[MAX_LINE_LEN]; + CHAR8 *FormatString; + INTN FormatLength; GUID_TO_BASENAME *GPtr; if ((Fptr = fopen (LongFilePath (FileName), "r")) == NULL) { @@ -2171,17 +2184,44 @@ Returns: return EFI_DEVICE_ERROR; } + // + // Generate the format string for fscanf + // + FormatLength = snprintf ( + NULL, + 0, + "%%%us %%%us", + (unsigned) sizeof (GPtr->Guid) - 1, + (unsigned) sizeof (GPtr->BaseName) - 1 + ) + 1; + + FormatString = (CHAR8 *) malloc (FormatLength); + if (FormatString == NULL) { + fclose (Fptr); + return EFI_OUT_OF_RESOURCES; + } + + snprintf ( + FormatString, + FormatLength, + "%%%us %%%us", + (unsigned) sizeof (GPtr->Guid) - 1, + (unsigned) sizeof (GPtr->BaseName) - 1 + ); + while (fgets (Line, sizeof (Line), Fptr) != NULL) { // // Allocate space for another guid/basename element // GPtr = malloc (sizeof (GUID_TO_BASENAME)); if (GPtr == NULL) { + free (FormatString); + fclose (Fptr); return EFI_OUT_OF_RESOURCES; } memset ((char *) GPtr, 0, sizeof (GUID_TO_BASENAME)); - if (sscanf (Line, "%s %s", GPtr->Guid, GPtr->BaseName) == 2) { + if (sscanf (Line, FormatString, GPtr->Guid, GPtr->BaseName) == 2) { GPtr->Next = mGuidBaseNameList; mGuidBaseNameList = GPtr; } else { @@ -2192,6 +2232,7 @@ Returns: } } + free (FormatString); fclose (Fptr); return EFI_SUCCESS; }