Don't access a note entry in case namesz is less than 1

This commit is contained in:
Serge Lamikhov-Center 2020-05-29 05:26:43 -07:00
parent a935b5472e
commit 453929342f
3 changed files with 43 additions and 5 deletions

25
.vscode/launch.json vendored
View File

@ -5,7 +5,7 @@
"version": "0.2.0",
"configurations": [
{
"name": "g++ build and debug active file",
"name": "Run ELFIO Tests",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/ELFIOTest/ELFIOTest",
@ -22,7 +22,28 @@
"ignoreFailures": true
}
],
"preLaunchTask": "g++ build",
"preLaunchTask": "ELFIO Test build",
"miDebuggerPath": "/usr/bin/gdb"
},
{
"name": "Run ELF Dump",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/examples/elfdump/elfdump",
"args": ["test"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "ELF Dump Build",
"miDebuggerPath": "/usr/bin/gdb"
}
]

18
.vscode/tasks.json vendored
View File

@ -2,7 +2,7 @@
"tasks": [
{
"type": "shell",
"label": "g++ build",
"label": "ELFIO Test build",
"command": "make",
"args": [
"INCLUDES=-I..",
@ -15,6 +15,22 @@
"kind": "build",
"isDefault": true
}
},
{
"type": "shell",
"label": "ELF Dump Build",
"command": "make",
"args": [
"INCLUDES=-I..",
"CXXFLAGS='-g -O0'"
],
"options": {
"cwd": "${workspaceRoot}",
},
"group": {
"kind": "build",
"isDefault": true
}
}
],
"version": "2.0.0"

View File

@ -74,9 +74,10 @@ class note_section_accessor_template
const endianess_convertor& convertor = elf_file.get_convertor();
type = convertor( *(const Elf_Word*)( pData + 2*align ) );
Elf_Word namesz = convertor( *(const Elf_Word*)( pData ) );
descSize = convertor( *(const Elf_Word*)( pData + sizeof( namesz ) ) );
descSize = convertor( *(const Elf_Word*)( pData + sizeof( namesz ) ) );
Elf_Xword max_name_size = note_section->get_size() - note_start_positions[index];
if ( namesz > max_name_size ||
if ( namesz < 1 ||
namesz > max_name_size ||
namesz + descSize > max_name_size ) {
return false;
}