Public bug reported:

Hello,

I would report that execve() function works differently on Ubuntu 16.04
than on Fedora 24.

Here is my code that I tested:

#include <unistd.h>

int main() {
     char *const params[] = {"/usr/bin/perl", "/tmp/script.pl", NULL};
     char *const env[] = {NULL};
     execve(params[0], params, env);
}

On Ubuntu 16.04 it gives:
$ ./a.out 
OUTPUT=>~

EXITCODE=>0


On Fedora 24 it gives:
$ ./a.out 
OUTPUT=>/home/gani

EXITCODE=>0

The script.pl content is following:

#!/usr/bin/perl -w
my $output = `echo ~`;
my $exitcode = $?;
print "OUTPUT=>$output\n";
print "EXITCODE=>$exitcode\n";


I found it when CGI scripts ran by my Lighttpd web server caused a bug. I 
reviewed the Lighttpd code and I found that the web server uses the execve() to 
run CGI scripts. On Ubuntu 16.04 the execve() is not able to use ~ character as 
shortcut to home directory.

When CGI scripts execute a script (or program) that uses ~ somehwere in
code then it fails because ~ is no longer a pointer to home directory.

I am not C programmer, but I reviewed execve() description:

http://man7.org/linux/man-pages/man2/execve.2.html

to be sure that the HOME environment variable should be available for
scripts executed by execve().

On both my operating systems the HOME environment variable is set
properly and it looks the same for both (for the same user):

$ echo $HOME
/home/gani

Here are my two environments that I used to tests:

Ubuntu 16.04
 - glibc: 2.23
 - gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.1)
 - main system partition:
/dev/sda1 on / type ext4 (rw,relatime,errors=remount-ro,data=ordered)

Fedora 24
 - glibc: 2.23.1
 - gcc: version 5.3.1 20160406 (Red Hat 5.3.1-6) (GCC)
 - gcc: version 6.1.1 20160621 (Red Hat 6.1.1-3) (GCC)
 - main system partition:
/dev/sdc3 on / type ext4 (rw,relatime,data=ordered)


I added mount options above because I read in the execve() description that 
"nosuid" mount option can have meaning for execve(). As you can see, I don't 
use nosuid mount option.

For Fedora 24 I pointed two gcc (5.3.1 and 6.1.1). On both versions
execve() behaves the same and it returns valid home dir path in place ~.

I also tried PHP scripts and the execve() treated them the same as my
Perl script. If it can be useful, I past its content here:

<?php
exec('echo ~', $output, $exitcode);
$output = print_r($output, true);
echo "OUTPUT=>$output" . PHP_EOL;
echo "EXITCODE=>$exitcode" . PHP_EOL;
?>

To use it, please change this line:

char *const params[] = {"/usr/bin/perl", "/tmp/script.pl", NULL};

to this form:

char *const params[] = {"/usr/bin/php-cgi", "/tmp/script.php", NULL};

On Ubuntu 16.04 it gives:
$ ./a.out 
Content-type: text/html; charset=UTF-8

OUTPUT=>Array
(
    [0] => ~
)

EXITCODE=>0

On Fedora 24 it gives:
$ ./a.out 
X-Powered-By: PHP/5.6.23
Content-type: text/html; charset=UTF-8

OUTPUT=>Array
(
    [0] => /home/gani
)

EXITCODE=>0

I am not sure if it is caused directly by gcc, however my knowledge ends
here and I am not able to debug it deeper. If you will need some
additional tests or outputs, do not hesistate to ask me here.

Thank you in advance for your help with solving it.

Best regards.
Marcin Haba

** Affects: gcc (Ubuntu)
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1610553

Title:
  execve() misses tilde meaning

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/gcc/+bug/1610553/+subscriptions

-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to