diff --git a/.vscode/launch.json b/.vscode/launch.json index 27fdcbfbf21e05df4cc4a495f042940c8b6d6e17..df9d82deef65193c6f70391522809e59f3c377ba 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -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" } ] diff --git a/.vscode/tasks.json b/.vscode/tasks.json index bb508cf811106b238e721565861676296ecd8fc6..5ff6952e408eef59f56cd1bb35e07e81e6da8dd9 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -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" diff --git a/elfio/elfio_note.hpp b/elfio/elfio_note.hpp index 8619c7385dbdfdab8b7b571cd0409466550b22f2..fad615ec0c325d89768ae17f7880855be5ec9357 100644 --- a/elfio/elfio_note.hpp +++ b/elfio/elfio_note.hpp @@ -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; }