mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] execvp() behaviour with unrecognized file header
@ 2020-02-12 13:54 Alexander Scherbatiy
  2020-02-12 14:13 ` A. Wilcox
  2020-02-13 20:11 ` Markus Wichmann
  0 siblings, 2 replies; 8+ messages in thread
From: Alexander Scherbatiy @ 2020-02-12 13:54 UTC (permalink / raw)
  To: musl

Hello,

execvp() works differently on Linux Alpine and Ubuntu if it is called 
with a file which does not contain a proper shebang line. The file is 
executed on Ubuntu. It results to  ENOEXEC error on Linux Alpine.

man execvp on Ubuntu has description: "If the header of a file isn't 
recognized (the attempted execve(2) failed with the error ENOEXEC), 
these functions will execute the shell (/bin/sh) with the path of the 
file as its first argument."

Does execvp() from musl behaves differently by purpose in this case?


The sample code:

---- execvp_sample.c  ----

#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>

int main(int argc, char* argv[]) {

     char *file = argv[1];
     char *execvp_argv[1] = {NULL};
     execvp(file, execvp_argv);
     exit(errno);
}
--------------------------------------

gcc -o execvp_sample execvp_sample.c

---- script_1.sh ---

#!/bin/bash
echo Hello, World!

----------------------

Ubuntu: > ./execvp_sample ./script_1.sh

Hello, World!

---- script_2.sh ---

#!/bin/ash

echo Hello, World!

----------------------

Alpine Linux: > ./execvp_sample ./script_2.sh

Hello, World!

---- script_3.sh ---

echo Hello, World!

----------------------

Ubuntu: > ./execvp_sample ./script_3.sh

Hello, World!

Alpine Linux: > ./execvp_sample ./script_3.sh

error code: ENOEXEC


Thanks,

Alexander.


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-02-13 23:21 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-12 13:54 [musl] execvp() behaviour with unrecognized file header Alexander Scherbatiy
2020-02-12 14:13 ` A. Wilcox
2020-02-12 14:27   ` Rich Felker
2020-02-12 20:01     ` A. Wilcox
2020-02-13 10:02     ` Micha Nelissen
2020-02-13 18:29       ` Rich Felker
2020-02-13 20:11 ` Markus Wichmann
2020-02-13 23:21   ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).