Go to:
Gentoo Home
Documentation
Forums
Lists
Bugs
Planet
Store
Wiki
Get Gentoo!
Gentoo's Bugzilla – Attachment 271177 Details for
Bug 364877
sys-apps/sandbox issue with static binaries, pipes and FD_CLOEXEC
Home
|
New
–
[Ex]
|
Browse
|
Search
|
Privacy Policy
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
Testcase to demonstrate the bug (require static.c)
sandbox_exec_bug.c (text/plain), 1.52 KB, created by
Victor Stinner
on 2011-04-25 23:55:31 UTC
(
hide
)
Description:
Testcase to demonstrate the bug (require static.c)
Filename:
MIME Type:
Creator:
Victor Stinner
Created:
2011-04-25 23:55:31 UTC
Size:
1.52 KB
patch
obsolete
>#include <stdio.h> >#include <stdlib.h> >#include <fcntl.h> >#include <unistd.h> >#include <sys/wait.h> > >void cloexec(int fd) >{ > int flags; > > flags = fcntl(fd, F_GETFD); > if (flags == -1) { > perror("fcntl(F_GETFD)"); > exit(1); > } > fcntl(fd, F_SETFD, flags | FD_CLOEXEC); >} > >int main() >{ > int err; > pid_t child; > int outpipe[2]; > int errpipe[2]; > ssize_t n; > char buffer[4096]; > char* child_argv[] = {"./static", NULL}; > > err = pipe(outpipe); > if (err) { > perror("open"); > exit(1); > } > > err = pipe(errpipe); > if (err) { > perror("open"); > exit(1); > } > cloexec(errpipe[0]); > cloexec(errpipe[1]); > > child = fork(); > if (child < 0) { > perror("fork"); > exit(1); > } > if (child == 0) { > close(outpipe[0]); > close(errpipe[0]); > > dup2(outpipe[1], 1); > execv("./static", child_argv); > > perror("execl"); > exit(1); > } else { > close(outpipe[1]); > close(errpipe[1]); > > printf("wait errpipe..."); fflush(stdout); > n = read(errpipe[0], buffer, sizeof(buffer)); > if (n < 0) { > perror("fcntl(F_GETFD)"); > exit(1); > } > printf(" done\n"); > > while (1) { > n = read(outpipe[0], buffer, sizeof(buffer)); > if (n < 0) { > perror("fcntl(F_GETFD)"); > exit(1); > } > if (n == 0) > break; > } > > waitpid(child, NULL, 0); > exit(0); > } >} > >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 364877
: 271177 |
271179