diff options
| author | Stewart Smith <stewart@linux.vnet.ibm.com> | 2015-12-08 19:14:05 +1100 |
|---|---|---|
| committer | Stephen Cprek <smcprek@us.ibm.com> | 2016-02-19 15:31:32 -0600 |
| commit | 2cae5d32fd564af2024ad028e8fcd8bec081e23d (patch) | |
| tree | 23f02c1850524891f5c33b4a840a87c844ec1841 /src/build/linker | |
| parent | 88ee79c12059a76bafcbdc0b841100630eb18bb7 (diff) | |
| download | talos-hostboot-2cae5d32fd564af2024ad028e8fcd8bec081e23d.tar.gz talos-hostboot-2cae5d32fd564af2024ad028e8fcd8bec081e23d.zip | |
linker/gensyms: Check length of line read from objdump
Otherwise, when run with valgrind on my fedora 23 laptop:
==27841== Thread 2:
==27841== Conditional jump or move depends on uninitialised value(s)
==27841== at 0x4028AE: read_module_symbols(void*) (gensyms.C:308)
==27841== by 0x4E3C609: start_thread (pthread_create.c:334)
==27841== by 0x59EFA9C: clone (clone.S:109)
==27841==
Change-Id: Ib1540baddc8d32013208df86b871546bc24461fa
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Signed-off-by: Patrick Williams <iawillia@us.ibm.com>
Forwardport: Yes
Github: close open-power/hostboot#40
Reviewed-on: http://gfw160.aus.stglabs.ibm.com:8080/gerrit/23178
Tested-by: Jenkins Server
Reviewed-on: http://gfw160.aus.stglabs.ibm.com:8080/gerrit/23182
Diffstat (limited to 'src/build/linker')
| -rw-r--r-- | src/build/linker/gensyms.C | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/build/linker/gensyms.C b/src/build/linker/gensyms.C index acd1f8d3e..ccd7225f0 100644 --- a/src/build/linker/gensyms.C +++ b/src/build/linker/gensyms.C @@ -5,7 +5,7 @@ /* */ /* OpenPOWER HostBoot Project */ /* */ -/* Contributors Listed Below - COPYRIGHT 2013,2014 */ +/* Contributors Listed Below - COPYRIGHT 2013,2015 */ /* [+] International Business Machines Corp. */ /* */ /* */ @@ -302,10 +302,12 @@ void* read_module_symbols(void* input) { if (NULL == fgets(line, 1024, pipe)) break; + size_t linelen = strlen(line); + // Skip absolute values (ex. constants) and undefined symbols. if (strstr(line, "*ABS*") || strstr(line, "*UND*")) continue; // Skip section symbols (marked by 'd' in the 22nd column). - if ('d' == line[22]) continue; + if (linelen > 22 && 'd' == line[22]) continue; // First part of an objdump line is the symbol address, parse that. uint64_t line_address; @@ -315,14 +317,16 @@ void* read_module_symbols(void* input) // Determine if the symbol is a function and if it is in the .rodata // section. Symbols in the .rodata section have a slightly longer // line than those in the .text/.data sections (by 2 characters). - bool is_function = ('F' == line[23]); + bool is_function = (linelen > 23 && 'F' == line[23]); size_t rodata = (NULL != strstr(line, ".rodata")) ? 2 : 0; // Parse the symbol size. uint64_t symbol_size; - if (1 != sscanf(&line[32+rodata], "%lx", &symbol_size)) continue; + if (linelen > 32+rodata && + 1 != sscanf(&line[32+rodata], "%lx", &symbol_size)) continue; // Parse the function name. + assert(linelen > 48+rodata); string function = &line[48+rodata]; function.resize(function.length() - 1); // remove the newline. |

