alvaro
1a3cb25a7c
Fix oob read terminating data with 0
...
Fix crash e3c41070342cf84dea077356ddbb8ebf4326a601
==12073==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6110000003bb at pc 0x0000004c234c bp 0x7fcf6359ec30 sp 0x7fcf6359e3
e0
READ of size 11 at 0x6110000003bb thread T0
#0 0x4c234b in __interceptor_strlen.part.30 /home/alvaro/tools/llvm/llvm/projects/compiler-rt/lib/asan/../sanitizer_common/sanitize
r_common_interceptors.inc:301
#1 0x7165e6579d87 in std::char_traits<char>::length(char const*) /build/gcc-multilib/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3
/include/bits/char_traits.h:269
#2 0x7165e6579d87 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std
::allocator<char> const&) /build/gcc-multilib/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.h:495
#3 0x5c3333 in ELFIO::elfio::load_sections(std::istream&) /home/alvaro/fuzzers/elfio/ELFIO/examples/libfuzzer/../../elfio/elfio.hpp
:413:44
2017-10-04 20:47:51 +03:00
alvaro
39f8614f17
Added stream_size into section
...
This will allow to perform some security checks when reading size values
from ELF file
Fix crash e1ce7cecf01cf800397a4302854d9d76fa19763c
2017-10-04 20:47:51 +03:00
Vašek Potoček
972f89e022
Better support for read-only ELF access
2017-10-04 20:33:10 +03:00
Vašek Potoček
ced83b14be
More 386 relocation types
2017-10-04 20:15:53 +03:00
Serge Lamikhov-Center
fbf8eafc2d
Permit updating of e_version field of ELF header
2017-03-28 00:35:17 +03:00
Martin Bickel
b4127676ba
Fix calculation of section alignment
2017-03-06 22:28:46 +02:00
Martin Bickel
3385408d6b
Rephrase condition of is_sect_in_seg() to make it more intuitive
2017-03-06 22:28:46 +02:00
Martin Bickel
fe78d06e81
Segment align updated when saving, not loading
...
After loading, the data model in memory should resemble the original ELF file as closely as possible,
so that ELF viewers based on elfio will print out the original values, not the calculated ones.
2017-02-18 19:25:21 +02:00
Martin Bickel
6c19078803
Fixed section to segment mapping for 0-length sections
2017-02-18 19:25:21 +02:00
Martin Bickel
d800c7b295
When saving a previously loaded ELF file, don't shrink segments' memory size
2017-01-16 20:38:37 +02:00
Martin Bickel
213dbedac2
Add sanity check when calculating alignment
2017-01-16 20:38:37 +02:00
Martin Bickel
fb5ec079ba
new method for validating the loaded ELF file
2017-01-16 20:38:37 +02:00
Martin Bickel
d0cb172474
Expose getter for section.offset
2017-01-16 20:38:37 +02:00
Martin Bickel
a0de1960d6
Check for errors when loading segments
2017-01-16 20:38:37 +02:00
Serge Lamikhov-Center
878247108f
Ignore sections of zero size. Thanks to Martin Bickel
2016-12-20 20:11:20 +02:00
Tobias Klauser
446e0c215c
elfio_note: fix MSVC compiler warning
...
Fix the following MSVC compiler warning:
elfio/elfio_note.hpp(77): warning C4267: 'initializing' : conversion from 'size_t' to 'ELFIO::Elf_Word', possible loss of data
by changing the type of max_name_sizei to Elf_Xword, as
note_secton->get_size() returns Elf_Xword and note_start_positions also
contains members of type Elf_Xword.
2016-10-06 12:07:20 +02:00
Tobias Klauser
af4140a122
elfio: don't cast away const qualifiers
...
Don't cast away const qualifiers when accessing const data (e.g. section
data). This fixes the warnings such as the following when compiling with
GCC and the -Wcast-qual flag set:
warning: cast from type ‘const char*’ to type ‘ELFIO::Elf_Word* {aka unsigned int*}’ casts away qualifiers [-Wcast-qual]
2016-09-22 23:22:39 +03:00
Yutetsu TAKATSUKASA
fb26cf1002
resolve compiler warning by "-Wsign-compare"
2016-09-18 10:44:16 +09:00
Serge Lamikhov-Center
b2525656a5
New e_machine numbers added
2016-07-10 12:36:52 +03:00
Serge Lamikhov-Center
3c5620d46d
Make note section entries for 64-bit ELF file be the same as for 32-bit file
...
There are discrepancies in documentations. SCO documentation
(http://www.sco.com/developers/gabi/latest/ch5.pheader.html#note_section )
requires 8 byte entries alignment for 64-bit ELF file,
but Oracle's definition uses the same structure
for 32-bit and 64-bit formats.
(https://docs.oracle.com/cd/E23824_01/html/819-0690/chapter6-18048.html )
It looks like EM_X86_64 Linux implementation is similar to Oracle's
definition. Therefore, the same alignment works for both formats
2016-07-10 11:35:23 +03:00
Kevin Klues
e3e0d6dbdb
Fixed off-by-one error in 'name' of add_note() function.
...
Previously, when assigning 'name' as a string, it's length was specified
using the full length of 'namesz'. However, this length includes the
trailing '\0' of the underlying char[]. This ultimately causes the C++
string that is created to (incorrectly) contain the '\0' character as
well. This leads to problems where e.g. the following will return false,
even when 'name' itself actually contains the string "GNU\0":
if (name == "GNU") {
return true;
}
return false;
To fix this, we should only include the length of the string minus the
trailing '\0'.
2016-07-02 11:02:20 -07:00
Serge Lamikhov-Center
8e7a29e128
Refactoring
2016-04-23 17:58:34 +03:00
Tim Strazzere
ecc45ede27
Prevent accessing pdata struct if it doesn't exist.
2016-04-23 16:37:48 +03:00
Tim Strazzere
88503347da
Avoid SIGSEV due to non-existant string section.
2016-04-23 16:37:48 +03:00
Tim Strazzere
812f7299b3
Avoid SIGABRT due to over allocating during new instance of objects.
2016-04-23 16:37:48 +03:00
Serge Lamikhov-Center
69b6177bd6
Make '.shstrtab' section be explicitly aligned to 1
2015-09-26 15:01:56 +03:00
Serge Lamikhov-Center
f2e17bac87
Fix offset calculation for the case where section's align field is zero
2015-09-26 11:07:26 +03:00
Serge Lamikhov-Center
3429026ab7
Include <iterator> header file
2015-08-22 20:04:02 +03:00
Serge Lamikhov-Center
b88df7bda8
The list of machine architectures was updated
2015-04-30 18:16:03 +03:00
Serge Lamikhov-Center
5ec1fc8949
Prevent a crash when working with MN10300 ELF file
2015-02-25 00:57:51 +02:00
Serge Lamikhov-Center
c45e81fd32
String section accessor refactoring
2015-02-21 13:50:32 +02:00
Serge Lamikhov-Center
9e4502d90e
Copyright year update
2015-02-13 20:51:07 +02:00
Serge Lamikhov-Center
8290078a64
Relocation entry endianness fix; Warnings elimination
2015-02-13 20:47:37 +02:00
Mario Werner
91e61ec4b2
use the NULL section instead of offset == 0
...
This change makes it possible to use the regular API to build up
elf files which include the file header.
2014-12-03 10:38:44 +01:00
Mario Werner
d2a27c7d96
initialized a few variables to silence warnings when building with Wall
2014-12-03 09:45:21 +01:00
Mario Werner
1676247836
fix alignment of segments during saving -> copied elfs are working
...
The old implementation aligned the segment start. However, the
intended behaviour is to align the offset and the vaddr
(p_vaddr % p_align == p_offset % p_align). This is required for the
loader which can then operate on memory pages.
2014-12-03 09:27:56 +01:00
Mario Werner
fe0c85995d
add 4 byte alignment for the section table
...
this is probably not required but definitely does not hurt
2014-12-03 09:24:21 +01:00
Serge Lamikhov-Center
1db119a8ca
Refactoring - a nicer code for is_subsequence_of()
...
Conflicts:
elf_examples/asm_copy
2014-11-23 00:53:19 +02:00
Mario Werner
b91a43b378
special support for PHDR segments and segments which include the elf header
...
Only elf files with strange GNU_RELRO segments fail the load, save, cycle.
It would maybe a good idea to separate the layout functionality from the
current save. The current coupling of layout and save make it
impossible to build layouts which contain the elf header via the public
API.
2014-11-15 22:08:52 +01:00
Mario Werner
755b92c580
move the section table to the end of the elf file
2014-11-14 13:40:25 +01:00
Mario Werner
c743d0bf74
separated layout generation and saving
...
Many example elfs (hello_32, hello_64, asm ...) require that the
first section directly follows the program header table. The
section header is then placed between segments or at the end.
This change prepares the late placement of section header table.
2014-11-14 13:06:39 +01:00
Mario Werner
55c2841e47
changed order in which the sections are emitted
...
The fact that segments can contain header information as well as
sections requires that sections within segments are emitted first.
2014-11-14 10:37:50 +01:00
Mario Werner
0ece76b5eb
rewrote the segment save logic to not only care about alignment
...
The initial implementation only made sure that all sections and segments
are properly aligned. This is enough for simple embedded applications
but can not deal with more complex layouts.
The new implementation should be more generic given that it respects the
virtual addresses of the individual sections.
One thing which is currently not supported by this rewrite are segments
which contain the program/segment header or even the whole elf header.
2014-11-14 08:27:36 +01:00
Mario Werner
e5592ddfdd
fix: make segment loading similar to readelf's algorithm
...
ALLOC sections are now matched against the virtual address space of
the segment. Non ALLOC sections still use the offset approach.
2014-11-14 08:04:55 +01:00
Mario Werner
8dda93f2bb
fixed a few warnings (signed-unsigned comparisions, unused param)
2014-11-13 18:24:03 +01:00
Mario Werner
22bd7ba77d
fix: static class member MAX_DATA_ENTRIES is not defined -> linker error
...
Static class members usually have to be defined explicitly which plays not
well with header only libraries. Moving the constant into the ELFIO scope
works around that problem.
The problem only shows up at -O0. Higher optimisations levels manage to
completely remove the references to the static member.
2014-11-13 18:23:02 +01:00
Semi Malinen
5000c533ba
Add const
2014-10-30 14:47:14 +02:00
Semi Malinen
695a05dc5d
Do not index past the end of the chain table
2014-10-30 14:29:33 +02:00
Serge Lamikhov-Center
7dd7dade6f
Non-significant formatting
2014-08-09 10:56:18 +03:00
Vincent Huang
6d713f4d0a
Added iterator for segments and sections
...
segments and sections were already stored as std::vector<T>.
This change simply exposes the std::vector<T>::iterator functions.
2014-08-07 23:12:35 -04:00
Serge Lamikhov-Center
33dcaf063f
Use [i|o]stream instead of [i|o]fstream; The patch was provided by Jason Hiser
...
Test's fixes
2014-02-26 18:02:30 +02:00
Serge Lamikhov-Center
e8afffece9
Dump for section and segment data added
2014-02-26 17:35:20 +02:00
Serge Lamikhov-Center
17f03740e6
Using macros for header fields access functions
...
Set segment's index upon its creation
Move to VS2013 projects
2014-02-26 17:30:43 +02:00
Mario Werner
1d2930abc7
redesigned save_segments_and_their_sections
...
We have some elf files where a section (.ARM.exidx) is located in multiple segments.
To keep this property it is necessary to keep track of the emitted sections.
Furthermore, the correct sequence for the segment emission has to be determined.
This is done by postponing segments which are actually a subsequence of another segment.
Additionally the alignment is not considered as part of the file size of a segment anymore.
2014-02-17 11:52:25 +01:00
Mario Werner
5dd8ba29bd
assign sections to the segments during load based on the offsets
2014-02-13 18:59:16 +01:00
Mario Werner
f78a519522
removed const from the segment load function
2014-02-13 18:45:17 +01:00
Serge Lamikhov-Center
ed600e64f3
Ticket #10 : Fix section type SHT_NOBITS file_size calculation
2013-05-16 17:58:09 +03:00
Serge Lamikhov-Center
ed6a40ada1
Proper calculate size difference between file_size/memory_size in case of section type SHT_NOBITS
2013-04-21 16:54:07 +03:00
Serge Lamikhov-Center
ec5ca1fa17
Ticket #9 : Segment offset written in wrong endianess.
2013-04-20 01:27:29 +03:00
Serge Lamikhov-Center
2ced96026d
Remove 'mutable' specification in 'section' class
2013-03-21 02:13:50 +02:00
Serge Lamikhov-Center
79ecb3fabc
Data size boundary check for dynamic section reader
...
Permit section data allocation for size equal to 0
2013-01-30 14:45:35 +02:00
Serge Lamikhov-Center
cde39c9d45
Add a validation for the case when dynamic section has no data
...
Signed-off-by: Serge Lamikhov-Center <to_serge@users.sourceforge.net>
2013-01-30 01:06:00 +02:00
Serge Lamikhov-Center
b217a8a993
Remove extra ";" to prevent warnings at compilation with GCC -pedantic option
2013-01-30 01:05:32 +02:00
Serge Lamikhov-Center
1e82ef11b4
add_entry() functions are implemented for dynamic_section_accessor class
...
Signed-off-by: Serge Lamikhov-Center <to_serge@users.sourceforge.net>
2013-01-13 19:59:15 +02:00
Serge Lamikhov-Center
4b7061dc92
Dynamic section accessor is implemented
...
Fix segment header position when no segments are present
Dumper - dynamic section output added
Dynamic section reader tests are added
Signed-off-by: Serge Lamikhov-Center <to_serge@users.sourceforge.net>
2013-01-13 04:29:43 +02:00
Serge Lamikhov-Center
0953467246
Added output for 64-bit ELF files
2012-12-02 19:01:05 +02:00
Serge Lamikhov-Center
b78c0aca3d
Convert all files to UNIX EOL
2012-11-27 11:45:28 +02:00
Serge Lamikhov-Center
001833f402
Don't print \0 at the end of notes
2012-11-26 01:17:00 +02:00
Serge Lamikhov-Center
b74f44443d
'add_entry' in symbol_section_accessor was renamed to 'add_symbol'
...
documentation update
<elfio.hpp> was modified to be <elfio/elfio.hpp>
2012-11-25 19:58:07 +02:00
Serge Lamikhov-Center
d3a0732983
Use <elfio/> prefix for \#include files
2012-11-25 14:37:09 +02:00
Serge Lamikhov-Center
647aa544be
Remove tabs; Fix line endianess
2012-11-25 00:23:05 +02:00
Serge Lamikhov-Center
16e9c36e28
Document updates; Small refactoring
2012-11-20 19:58:28 +02:00
Serge Lamikhov-Center
2d514544fc
- Add const attribute to several functions of section interface
...
- Doc change
2012-09-18 14:21:21 +03:00
Serge Lamikhov-Center
ac33c1e4de
Output section names at the end of line
...
Increase width of Nr field
Refactor format_assoc() implementation
2012-08-23 09:12:03 +03:00
Serge Lamikhov-Center
3aa0cc1751
Align format_assoc() implementation to its specialization version
2012-08-22 22:50:03 +03:00
Serge Lamikhov-Center
f0211fa620
Use 'const' instance when working with dumper
...
Use a template for tabled functions
2012-08-22 19:56:35 +03:00
Serge Lamikhov-Center
3b43ddd6b9
ELFDump is using ELFIO::dump class now
2012-08-19 23:26:47 +03:00
Serge Lamikhov-Center
d8a7e8ccca
ELFDump is using ELFIO::dump class now
2012-08-19 22:06:01 +03:00
Serge Lamikhov-Center
8ded746bc3
Symbol tables and notes output added
2012-08-19 22:01:18 +03:00
Serge Lamikhov-Center
02696b9e7f
Segment dump implemented
2012-08-19 18:48:02 +03:00
Serge Lamikhov-Center
e62b2b38cb
Section flags output added
2012-08-19 15:07:54 +03:00
Serge Lamikhov-Center
4a2b8c1e85
Section output started
2012-08-18 21:05:11 +03:00
Serge Lamikhov-Center
ca0609fa4f
Type and Machine tables added to dumper
2012-08-18 13:08:35 +03:00
Serge Lamikhov-Center
cb56843e26
Headers dump is implemented by using tables
2012-08-18 08:50:03 +03:00
Serge Lamikhov-Center
e04476791a
Another change
2012-07-29 22:24:45 +03:00
Serge Lamikhov-Center
6d60be2dfd
A test program added; str_elf_class output implemented
2012-07-29 17:49:16 +03:00
Serge Lamikhov-Center
daa8c81bfb
Add dumper file
2012-07-29 17:49:16 +03:00
Serge Lamikhov-Center
3203483e34
Prevent compilation warnings when compiled x64 target with VS2008
2012-07-24 12:10:16 +03:00
Serge Lamikhov-Center
bf2efcc32f
Don't pass NULL pointer to set_name function
2012-07-24 00:00:11 +03:00
Serge Lamikhov-Center
d439d83458
Fix header.e_ident initialization
2012-07-21 09:17:18 +03:00
Serge Lamikhov-Center
e1d554978d
Trim trailing space and remove tabs
2012-06-24 09:02:32 +03:00
Serge Lamikhov-Center
2cddbab258
To make memory_size bigger than file_size, set memory_size prior calling 'save' function
2012-06-24 08:50:29 +03:00
Serge Lamikhov-Center
b3b7aed245
Declaration uses macro for section and segment
2012-06-23 19:41:42 +03:00
Serge Lamikhov-Center
00e37476c0
- Fix a reported problem with section data size not updating at 'load' time
2012-06-20 09:09:20 +03:00
Serge Lamikhov-Center
1a957edfba
Don't calculate section address if it was already initialized
2012-06-03 23:19:33 +03:00
Serge Lamikhov-Center
8e3eedac9a
Cosmetic
2012-03-11 22:39:27 +02:00
Serge Lamikhov-Center
9705f1ac35
Documentation update
2012-03-11 06:16:31 +02:00
Serge Lamikhov-Center
626ccc6cbd
Make load/save functions of section/segment - private
2012-03-10 20:41:00 +02:00
Serge Lamikhov-Center
185d87c138
Try to avoid -std=c++0x compilation flag
2012-03-09 22:42:53 +02:00
Serge Lamikhov-Center
03da533493
Starting new site building
2012-03-09 12:01:14 +02:00