diff options
author | Michael LeMay <michael.lemay@intel.com> | 2016-01-29 09:53:47 -0800 |
---|---|---|
committer | Yonghong Zhu <yonghong.zhu@intel.com> | 2016-02-17 13:23:59 +0800 |
commit | ea3e924a0c91e2dd7fbb5e2f79899367222f27eb (patch) | |
tree | cf9dae8970c44c6afd350845125c3eac66897c45 /BaseTools/Source/C/GenFw/Elf64Convert.c | |
parent | 621bb723a4e00cb93e8a94c6126de4976dde1d9e (diff) | |
download | edk2-platforms-ea3e924a0c91e2dd7fbb5e2f79899367222f27eb.tar.xz |
BaseTools/GenFw: Correct datatypes in diagnostic messages and check for string termination
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>
Diffstat (limited to 'BaseTools/Source/C/GenFw/Elf64Convert.c')
-rw-r--r-- | BaseTools/Source/C/GenFw/Elf64Convert.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/BaseTools/Source/C/GenFw/Elf64Convert.c b/BaseTools/Source/C/GenFw/Elf64Convert.c index 5afd2ab7ca..3b5f630103 100644 --- a/BaseTools/Source/C/GenFw/Elf64Convert.c +++ b/BaseTools/Source/C/GenFw/Elf64Convert.c @@ -21,6 +21,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include <io.h>
#endif
#include <assert.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -302,7 +303,15 @@ GetSymName ( assert(Sym->st_name < StrtabShdr->sh_size);
- return (UINT8*)mEhdr + StrtabShdr->sh_offset + Sym->st_name;
+ UINT8* StrtabContents = (UINT8*)mEhdr + StrtabShdr->sh_offset;
+
+ bool foundEnd = false;
+ for (UINT32 i = Sym->st_name; (i < StrtabShdr->sh_size) && !foundEnd; i++) {
+ foundEnd = StrtabContents[i] == 0;
+ }
+ assert(foundEnd);
+
+ return StrtabContents + Sym->st_name;
}
//
@@ -337,7 +346,7 @@ ScanSections64 ( mCoffOffset += sizeof (EFI_IMAGE_NT_HEADERS64);
break;
default:
- VerboseMsg ("%s unknown e_machine type. Assume X64", (UINTN)mEhdr->e_machine);
+ VerboseMsg ("%s unknown e_machine type %hu. Assume X64", mInImageName, mEhdr->e_machine);
mCoffOffset += sizeof (EFI_IMAGE_NT_HEADERS64);
break;
}
@@ -721,7 +730,7 @@ WriteSections64 ( }
Error (NULL, 0, 3000, "Invalid",
- "%s: Bad definition for symbol '%s'@%p or unsupported symbol type. "
+ "%s: Bad definition for symbol '%s'@%#llx or unsupported symbol type. "
"For example, absolute and undefined symbols are not supported.",
mInImageName, SymName, Sym->st_value);
|