Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date: Wed, 12 Feb 2020 16:54:37 +0300
From: Alexander Scherbatiy <alexander.scherbatiy@...l-sw.com>
To: musl@...ts.openwall.com
Subject: execvp() behaviour with unrecognized file header

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.

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.