bad_execv - int rv if(exec_common_fork!= 0 return rv =...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
/* * bad calls to execv() */ #include <sys/types.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> #include <err.h> #include "config.h" #include "test.h" static int exec_common_fork(void) { int pid, rv, status; pid = fork(); if (pid<0) { warn("UH-OH: fork failed"); return -1; } if (pid==0) { /* child */ return 0; } rv = waitpid(pid, &status, 0); if (rv == -1) { warn("UH-OH: waitpid failed"); return -1; } if (status != MAGIC_STATUS) { warnx("FAILURE: wrong exit code of subprocess"); } return 1; } static void exec_badprog(const void *prog, const char *desc) { int rv; char *args[2]; args[0] = (char *)"foo"; args[1] = NULL; if (exec_common_fork() != 0) { return; } rv = execv(prog, args); report_test(rv, errno, EFAULT, desc); exit(MAGIC_STATUS); }
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
static void exec_emptyprog(void) { int rv; char *args[2]; args[0] = (char *)"foo"; args[1] = NULL; if (exec_common_fork() != 0) { return; } rv = execv("", args); report_test2(rv, errno, EINVAL, EISDIR, "exec the empty string"); exit(MAGIC_STATUS); } static void exec_badargs(void *args, const char *desc)
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: { int rv; if (exec_common_fork() != 0) { return; } rv = execv("/bin/true", args); report_test(rv, errno, EFAULT, desc); exit(MAGIC_STATUS); } static void exec_onearg(void *ptr, const char *desc) { int rv; char *args[3]; args[0] = (char *)"foo"; args[1] = (char *)ptr; args[2] = NULL; if (exec_common_fork() != 0) { return; } rv = execv("/bin/true", args); report_test(rv, errno, EFAULT, desc); exit(MAGIC_STATUS); } void test_execv(void) { exec_badprog(NULL, "exec NULL"); exec_badprog(INVAL_PTR, "exec invalid pointer"); exec_badprog(KERN_PTR, "exec kernel pointer"); exec_emptyprog(); exec_badargs(NULL, "exec /bin/true with NULL arglist"); exec_badargs(INVAL_PTR, "exec /bin/true with invalid pointer arglist"); exec_badargs(KERN_PTR, "exec /bin/true with kernel pointer arglist"); exec_onearg(INVAL_PTR, "exec /bin/true with invalid pointer arg"); exec_onearg(KERN_PTR, "exec /bin/true with kernel pointer arg"); }...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern