[cs631apue] exec error

Hem Shah hshah42 at stevens.edu
Tue Nov 26 22:43:50 EST 2019


Hello Professor,

Sorry for the late reply, but here is the way I am able to reproduce it.

This was the cgi-script that I was executing from the program:

#!/bin/sh

echo "Content-Type: text/html"

echo


env

The code that does not work is:

#include <unistd.h>

#include <stdlib.h>

#include <string.h>

#include <errno.h>

#include <stdio.h>


int

main(int argc, char **argv) {

        (void) setenv("something", "something", 1);

        (void) execl("/cgi-bin/something.cgi", (char *) 0);

        printf("%s\n", strerror(errno));

        return 1;

}

This prints an error which is:
Bad Address

This, on the other hand, gives me the desired result:

#include <unistd.h>

#include <stdlib.h>

#include <string.h>

#include <errno.h>

#include <stdio.h>


int

main(int argc, char **argv) {

        (void) setenv("something", "something", 1);

        printf("\n"); /*additional line compared to previous code*/

        (void) execl("/cgi-bin/something.cgi", (char *) 0);

        printf("%s\n", strerror(errno));

        return 1;

}

result:


Content-Type: text/html


ENV=/root/.shrc

BLOCKSIZE=1k

PWD=/root/programs/sws/APUE-Group

MAIL=/var/mail/root

HOME=/root

PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/pkg/sbin:/usr/pkg/bin:/usr/X11R7/bin:/usr/local/sbin:/usr/local/bin

HOST=localhost

SSH_CONNECTION=10.0.2.2 62926 10.0.2.15 22

SSH_TTY=/dev/pts/1

TERM=xterm-256color

OLDPWD=/root/programs/sws

USER=root

SSH_CLIENT=10.0.2.2 62926 22

LOGNAME=root

SHELL=/bin/sh

something=something

Thank you for helping me with this!

Plus we also discussed on how to listen on all address, I found this which works:
setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, &off, sizeof(off))

Regards,
Hem Shah


________________________________
From: cs631apue-bounces at lists.stevens.edu <cs631apue-bounces at lists.stevens.edu> on behalf of Jan Schaumann <jschauma at stevens.edu>
Sent: Tuesday, November 26, 2019 7:03 PM
To: cs631apue at lists.stevens.edu <cs631apue at lists.stevens.edu>
Subject: [cs631apue] exec error

Hello,

One of you had reported a problem with setenv(2) and
exec(2), where the invocation of setenv(2) somehow
caused exec(2) to fail with EFAULT.

I can't seem to reproduce the issue -- could you send
your sample code that triggers this problem?

Thanks,
-Jan
_______________________________________________
cs631apue mailing list
cs631apue at lists.stevens.edu
https://lists.stevens.edu/mailman/listinfo/cs631apue
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.stevens.edu/pipermail/cs631apue/attachments/20191127/2f77cb3c/attachment.html>


More information about the cs631apue mailing list