haampie / libtree

ldd as a tree
MIT License
2.63k stars 60 forks source link

Symlink overwrites real file in deployment directory #20

Closed ekilmer closed 4 years ago

ekilmer commented 4 years ago

Very cool project!! 😄

Issue

While playing around with this, I found an issue when trying to collect and package dependencies for clang-11. The problem seems to be that the actual file, libclang-cpp.so.11, is being overwritten with a symlink of the same name.

I've added a simple check that should prevent this in my branch (https://github.com/haampie/libtree/compare/master...ekilmer:fix-symlink-clobber), which I can submit for a PR if you'd like.

Reproduce

I also made a Dockerfile for reproducing this, where you can switch repos to check that my patch fixes the problem.

Dockerfile:

# Build with `docker build -t clang-11-test .`
FROM ubuntu:19.10

# Setup for installation of clang-11
RUN apt-get update && apt-get install -y ca-certificates wget gnupg apt-utils && \
    wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
RUN echo "deb http://apt.llvm.org/eoan/ llvm-toolchain-eoan main\n\
          deb-src http://apt.llvm.org/eoan/ llvm-toolchain-eoan main" > /etc/apt/sources.list.d/clang.list
RUN apt-get update && apt-get install -y clang-11

# Build and Install libtree
RUN apt-get update && apt-get install -y git cmake build-essential
WORKDIR /project

# Change these lines to build from different repo
#RUN git clone --recursive --branch fix-symlink-clobber https://github.com/ekilmer/libtree
RUN git clone --recursive https://github.com/haampie/libtree

RUN mkdir -p libtree/build && cd libtree/build && \
    export CXX=clang++-11 && export CC=clang-11 && \
    cmake ../ && make -j4

# Run the test with `docker run --rm -t -i clang-11-test`
RUN apt-get update && apt-get install -y tree
CMD /project/libtree/build/libtree -a -d ./clang-11-deps /usr/bin/clang-11 && tree -C ./clang-11-deps

Run:

docker build -t clang-11-test .

docker run --rm -t -i clang-11-test

Output of tree on the deploy directory using master and showing the broken symlink for libclang-cpp.so.11:

Screen Shot 2020-04-16 at 12 09 06 PM

Output of tree for my branch fix-symlink-clobber by changing to these lines in Dockerfile

RUN git clone --recursive --branch fix-symlink-clobber https://github.com/ekilmer/libtree
#RUN git clone --recursive https://github.com/haampie/libtree

showing the fix and real file for libclang-cpp.so.11:

Screen Shot 2020-04-16 at 12 09 19 PM

haampie commented 4 years ago

Thanks for pointing this out, and feel free to open a PR, I would be happy! I mistakenly assumed the symlinks would always take the form libname.so.x -> libname.so.x.y.z.

haampie commented 4 years ago

See https://github.com/haampie/libtree/releases/tag/v1.1.2