Skip to content

Commit

Permalink
Merge pull request #420 from NixOS/flake-update
Browse files Browse the repository at this point in the history
Flake update
  • Loading branch information
Mic92 authored Oct 26, 2022
2 parents 0582e4d + 582a96a commit 2d6e7cf
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/patchelf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,14 @@ void ElfFile<ElfFileParamNames>::normalizeNoteSegments()
size_t start_off = rdi(phdr.p_offset);
size_t curr_off = start_off;
size_t end_off = start_off + rdi(phdr.p_filesz);

/* Binaries produced by older patchelf versions may contain empty PT_NOTE segments.
For backwards compatibility, if we find one we should ignore it. */
bool empty = std::none_of(shdrs.begin(), shdrs.end(),
[&](auto & shdr) { return rdi(shdr.sh_offset) >= start_off && rdi(shdr.sh_offset) < end_off; });
if (empty)
continue;

while (curr_off < end_off) {
/* Find a section that starts at the current offset. If we can't
find one, it means the SHT_NOTE sections weren't contiguous
Expand Down
5 changes: 3 additions & 2 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ src_TESTS = \
phdr-corruption.sh \
replace-needed.sh \
replace-add-needed.sh \
add-debug-tag.sh
add-debug-tag.sh \
empty-note.sh

build_TESTS = \
$(no_rpath_arch_TESTS)

TESTS = $(src_TESTS) $(build_TESTS)

EXTRA_DIST = no-rpath-prebuild $(src_TESTS) no-rpath-prebuild.sh invalid-elf endianness
EXTRA_DIST = no-rpath-prebuild $(src_TESTS) no-rpath-prebuild.sh invalid-elf endianness empty-note

TESTS_ENVIRONMENT = PATCHELF_DEBUG=1

Expand Down
Binary file added tests/empty-note
Binary file not shown.
12 changes: 12 additions & 0 deletions tests/empty-note.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#! /bin/sh -e

SCRATCH=scratch/$(basename $0 .sh)

rm -rf ${SCRATCH}
mkdir -p ${SCRATCH}
cp $(dirname $(readlink -f $0))/empty-note ${SCRATCH}/

# Running --set-interpreter on this binary should not produce the following
# error:
# patchelf: cannot normalize PT_NOTE segment: non-contiguous SHT_NOTE sections
../src/patchelf --set-interpreter ld-linux-x86-64.so.2 ${SCRATCH}/empty-note

0 comments on commit 2d6e7cf

Please sign in to comment.