Skip to content

Instantly share code, notes, and snippets.

@eagafonov
Last active March 27, 2024 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eagafonov/2d5bf9323f70e2ffb7285725aeb9dfe1 to your computer and use it in GitHub Desktop.
Save eagafonov/2d5bf9323f70e2ffb7285725aeb9dfe1 to your computer and use it in GitHub Desktop.
GNU Make's bug (exec a directory)
#!/bin/sh
set -x
# Create a folder named 'docker'. The folder would have 'executible' flag set
mkdir -p `pwd`/scripts/docker
# Add the script to the path BEFORE the rest
export PATH=`pwd`/scripts:$PATH
# Create a simple Makefile to run a docker command
cat<<EOF > Makefile
all:
docker ps
EOF
# Run the make command
make
# The output would be
# docker ps
# make: docker: Permission denied
# `strace` would reveal the mystery (with some sed magic to strip the private stuff)
strace -f -e execve make 2>&1 | sed "s|/home/$(whoami)/.*/scripts/docker|/path/to/scripts/docker|g"
# The output would be like:
#
# execve("/usr/bin/make", ["make"], 0x7ffd59f59e68 /* 72 vars */) = 0
# docker ps
# strace: Process 2833630 attached
# [pid 2833630] execve("/path/to/scripts/docker", ["docker", "ps"], 0x55884ea326f0 /* 75 vars */) = -1 EACCES (Permission denied)
# [pid 2833630] +++ exited with 127 +++
# make: docker: Permission denied
# make: *** [Makefile:2: all] Error 127
# Looks like make does not care if a command is a directory, but just checks for 'x' flag.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment