Skip to content

Instantly share code, notes, and snippets.

@0xef967c36 0xef967c36/herestring.c

Last active Mar 26, 2019
What would you like to do?
simple wrapper which will execute a command with its stdin redirected from a string
#define _GNU_SOURCE
#include <unistd.h>
#include <sys/syscall.h>
#include <string.h>
#include <err.h>
int main(int ac, char **av){
int fd; size_t len;
if(ac < 3) errx(1, "usage %s string cmd [args ...]", av[0]);
if((fd = syscall(SYS_memfd_create, av[0], 0)) == -1)
err(1, "memfd_create");
len = strlen(av[1]);
if(pwrite(fd, av[1], len, 0) != len) err(1, "pwrite");
if(dup2(fd, 0) == -1) err(1, "dup2");
if(fd != 0) close(fd);
execvp(av[2], av + 2);
err(1, "execvp %s", av[2]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.