Handle ENOTDIR in pathexec_run

From: Jacob Vosmaer via supervision <supervision_at_list.skarnet.org>
Date: Mon, 11 Nov 2019 18:00:21 +0100


First time on this list. Long time fan of Runit.

We have recently run into an edge case in Runit, which I think might
be worth patching.

If a user starts up runsvdir with existing-but-not-directory garbage
in their PATH,
runsvdir ends up in a broken state with a cryptic error. This is how
you can reproduce it:

mkdir -p svcs/foo
cat >svcs/foo/run <<EOF
echo hello world
while true; do
  sleep 1

chmod +x svcs/foo/run

PATH=/dev/null:$PATH runsvdir svcs

This will fail to launch runsv for svcs/foo. My understanding is this
happens because pathexec_run tries to call execve("/dev/null/runsv",
...) which fails with ENOTDIR.

Clearly this is a pathological PATH, but apparently there are people
out there who have this. And most other tools seem to ignore such
garbage entries. For example:

PATH=/dev/null:$PATH bash -c ls

The patch below makes runit ignore this type of bad path entry.

--- a/src/pathexec_run.c
+++ b/src/pathexec_run.c
_at_@ -35,7 +35,7 @@ void pathexec_run(const char *file,const char *
const *argv,const char * const *
     if (errno != error_noent) {
       savederrno = errno;
- if ((errno != error_acces) && (errno != error_perm) && (errno
!= error_isdir)) return;
+ if ((errno != error_acces) && (errno != error_perm) && (errno
!= error_isdir) && (errno != error_notdir)) return;

     if (!path[split]) {

What do you think?

Best regards,

Jacob Vosmaer
GitLab, Inc.
Received on Mon Nov 11 2019 - 17:00:21 UTC

This archive was generated by hypermail 2.3.0 : Sun May 09 2021 - 19:44:19 UTC