Skip to content

Commit

Permalink
Fix 449
Browse files Browse the repository at this point in the history
  • Loading branch information
rthomas committed Aug 27, 2020
1 parent 5f26216 commit 19e0675
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
14 changes: 9 additions & 5 deletions api/c/PE/Section.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@ void init_c_sections(Pe_Binary_t* c_binary, Binary* binary) {
Section& b_section = sections[i];
c_binary->sections[i] = static_cast<Pe_Section_t*>(malloc(sizeof(Pe_Section_t)));
std::vector<uint8_t> section_content = b_section.content();
uint8_t* content = static_cast<uint8_t*>(malloc(section_content.size() * sizeof(uint8_t)));
std::move(
std::begin(section_content),
std::end(section_content),
content);
uint8_t* content = nullptr;

if (section_content.size() > 0) {
content = static_cast<uint8_t*>(malloc(section_content.size() * sizeof(uint8_t)));
std::move(
std::begin(section_content),
std::end(section_content),
content);
}

c_binary->sections[i]->name = b_section.name().c_str();
c_binary->sections[i]->virtual_address = b_section.virtual_address();
Expand Down
2 changes: 1 addition & 1 deletion examples/c/pe_reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ int main(int argc, char **argv) {
section->entropy
);

if (section->size > 3) {
if (section->size > 3 && section->content != NULL) {
fprintf(stdout, "content[0..3]: %02x %02x %02x\n",
section->content[0], section->content[1], section->content[2]);
}
Expand Down
11 changes: 11 additions & 0 deletions scripts/cmake-config/lief-asan.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
cmake .. \
-DLIEF_DOC=off \
-DLIEF_PYTHON_API=off \
-DLIEF_EXAMPLES=on \
-DLIEF_C_API=on \
-DLIEF_LOGGING=off \
-DLIEF_ASAN=on \
-CMAKE_CXX_COMPILER=g++ \
-CMAKE_C_COMPILER=gcc \
-DCMAKE_BUILD_TYPE=RelWithDebInfo

0 comments on commit 19e0675

Please sign in to comment.