]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools/GenFw: Correct datatypes in diagnostic messages and check for string termin...
authorMichael LeMay <michael.lemay@intel.com>
Fri, 29 Jan 2016 17:53:47 +0000 (09:53 -0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Wed, 17 Feb 2016 05:23:59 +0000 (13:23 +0800)
This patch revises multiple diagnostic messages to use correct
datatypes.  It also checks that a symbol name that is about to be used
in a diagnostic message is terminated by a null character within the
contents of the string table section so that the print routine does
not read past the end of the string table section contents when
reading the symbol name.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Michael LeMay <michael.lemay@intel.com>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
BaseTools/Source/C/GenFw/Elf32Convert.c
BaseTools/Source/C/GenFw/Elf64Convert.c

index 41091e0888ba1acbe41e7e8c13f77970e3950352..d115291b062c9f4c3ae5f1876e467aeaa0ebe705 100644 (file)
@@ -21,6 +21,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <io.h>\r
 #endif\r
 #include <assert.h>\r
+#include <stdbool.h>\r
 #include <stdio.h>\r
 #include <stdlib.h>\r
 #include <string.h>\r
@@ -310,7 +311,15 @@ GetSymName (
 \r
   assert(Sym->st_name < StrtabShdr->sh_size);\r
 \r
-  return (UINT8*)mEhdr + StrtabShdr->sh_offset + Sym->st_name;\r
+  UINT8* StrtabContents = (UINT8*)mEhdr + StrtabShdr->sh_offset;\r
+\r
+  bool foundEnd = false;\r
+  for (UINT32 i = Sym->st_name; (i < StrtabShdr->sh_size) && !foundEnd; i++) {\r
+    foundEnd = StrtabContents[i] == 0;\r
+  }\r
+  assert(foundEnd);\r
+\r
+  return StrtabContents + Sym->st_name;\r
 }\r
 \r
 //\r
@@ -539,7 +548,7 @@ ScanSections32 (
     NtHdr->Pe32.OptionalHeader.Magic = EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC;\r
     break;\r
   default:\r
-    VerboseMsg ("%s unknown e_machine type. Assume IA-32", (UINTN)mEhdr->e_machine);\r
+    VerboseMsg ("%s unknown e_machine type %hu. Assume IA-32", mInImageName, mEhdr->e_machine);\r
     NtHdr->Pe32.FileHeader.Machine = EFI_IMAGE_MACHINE_IA32;\r
     NtHdr->Pe32.OptionalHeader.Magic = EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC;\r
   }\r
@@ -725,7 +734,7 @@ WriteSections32 (
           }\r
 \r
           Error (NULL, 0, 3000, "Invalid",\r
-                 "%s: Bad definition for symbol '%s'@%p or unsupported symbol type.  "\r
+                 "%s: Bad definition for symbol '%s'@%#x or unsupported symbol type.  "\r
                  "For example, absolute and undefined symbols are not supported.",\r
                  mInImageName, SymName, Sym->st_value);\r
 \r
index 5afd2ab7cab36bca7e2a95c853f7db3b0040e5f5..3b5f63010388ef692ef8b83528e868eab947833b 100644 (file)
@@ -21,6 +21,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <io.h>\r
 #endif\r
 #include <assert.h>\r
+#include <stdbool.h>\r
 #include <stdio.h>\r
 #include <stdlib.h>\r
 #include <string.h>\r
@@ -302,7 +303,15 @@ GetSymName (
 \r
   assert(Sym->st_name < StrtabShdr->sh_size);\r
 \r
-  return (UINT8*)mEhdr + StrtabShdr->sh_offset + Sym->st_name;\r
+  UINT8* StrtabContents = (UINT8*)mEhdr + StrtabShdr->sh_offset;\r
+\r
+  bool foundEnd = false;\r
+  for (UINT32 i = Sym->st_name; (i < StrtabShdr->sh_size) && !foundEnd; i++) {\r
+    foundEnd = StrtabContents[i] == 0;\r
+  }\r
+  assert(foundEnd);\r
+\r
+  return StrtabContents + Sym->st_name;\r
 }\r
 \r
 //\r
@@ -337,7 +346,7 @@ ScanSections64 (
     mCoffOffset += sizeof (EFI_IMAGE_NT_HEADERS64);\r
   break;\r
   default:\r
-    VerboseMsg ("%s unknown e_machine type. Assume X64", (UINTN)mEhdr->e_machine);\r
+    VerboseMsg ("%s unknown e_machine type %hu. Assume X64", mInImageName, mEhdr->e_machine);\r
     mCoffOffset += sizeof (EFI_IMAGE_NT_HEADERS64);\r
   break;\r
   }\r
@@ -721,7 +730,7 @@ WriteSections64 (
           }\r
 \r
           Error (NULL, 0, 3000, "Invalid",\r
-                 "%s: Bad definition for symbol '%s'@%p or unsupported symbol type.  "\r
+                 "%s: Bad definition for symbol '%s'@%#llx or unsupported symbol type.  "\r
                  "For example, absolute and undefined symbols are not supported.",\r
                  mInImageName, SymName, Sym->st_value);\r
 \r