[ create a new paste ] login | about

Link: http://codepad.org/VXbJUMQV    [ raw code | output | fork ]

C, pasted on Jun 10:
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

int make_popen(void) {
	FILE *fd = NULL;
	char buf[4096];
	size_t len = 0;
	fd = popen("/bin/echo hello world", "r");
	len = fread(buf, 1, 11, fd);
	if (len != 11) return 1;
	buf[11] = '\0';
	pclose(fd);
	if (strcmp(buf, "hello world") != 0) return 2;
	return 0;
}

int main(int argc, char **argv) {
	int success = -1;
	FILE *fd = NULL;
	assert(daemon(0, 0) == 0);
	fd = fopen("/tmp/result", "w");
	assert(fd != NULL);
	success = make_popen();
	fprintf(fd, "result: %i\n", success);
	fclose(fd);
	return success;
}


Output:
1
Disallowed system call: SYS_fork


Create a new paste based on this one


Comments: