From 0d0ee473fa73096cc7601a9169de4e2ac39d7163 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Fri, 25 Sep 2020 16:44:02 +0200 Subject: [PATCH] Detect windows line endings when executing a file Fixes #2783. --- src/postfork.cpp | 15 +++++++++++---- tests/checks/exec.fish | 10 ++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/postfork.cpp b/src/postfork.cpp index 6bb5b20aa..bf4cf0f10 100644 --- a/src/postfork.cpp +++ b/src/postfork.cpp @@ -360,10 +360,17 @@ void safe_report_exec_error(int err, const char *actual_cmd, const char *const * const char *interpreter = get_interpreter(actual_cmd, interpreter_buff, sizeof interpreter_buff); if (interpreter && 0 != access(interpreter, X_OK)) { - debug_safe(0, - "The file '%s' specified the interpreter '%s', which is not an " - "executable command.", - actual_cmd, interpreter); + // Detect windows line endings and complain specifically about them. + auto len = strlen(interpreter); + if (len && interpreter[len - 1] == '\r') { + debug_safe(0, + "The file uses windows line endings (\\r\\n). Run dos2unix or similar to fix it."); + } else { + debug_safe(0, + "The file '%s' specified the interpreter '%s', which is not an " + "executable command.", + actual_cmd, interpreter); + } } else { debug_safe(0, "The file '%s' does not exist or could not be executed.", actual_cmd); } diff --git a/tests/checks/exec.fish b/tests/checks/exec.fish index 067d0e07e..656156dce 100644 --- a/tests/checks/exec.fish +++ b/tests/checks/exec.fish @@ -9,5 +9,15 @@ not exec cat $f +chmod +x $f +$f +#CHECKERR: Failed to execute process '{{.*}}'. Reason: +#CHECKERR: The file uses windows line endings (\r\n). Run dos2unix or similar to fix it. + +# This needs to be last, because it actually runs exec. exec cat