Execve invoking

Tags: c shell exec
By : l245c4l
Source: Stackoverflow.com

I want to invoke a shell in C program by execve:

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

        char* path = "/bin/sh";
        int err = execve(path, &path, NULL);
        printf("%d\n", err);
        printf("%s\n", strerror(errno));
        printf("%x, %x\n", path, &path);

However the output is:

Bad address
80485c0, bf816f4c
By : l245c4l


Try this instead:

execl(path, path, NULL)

The exec family of functions will automatically execute a shell if the program is a script rather than a process image file. So you might be able to replace "path" with the pathname of the script.

This video can help you solving your question :)
By: admin