selinux-testsuite: fix unix/inet socket tests
PATCH v3 1/1 selinux-testsuite: fix unix/inet socket tests
There was a bug in the unix and inet socket tests:
the server program would exit as soon as it finished responding to the legitimate client, so the unauthorized client tests were "succeeding" due to the server socket not even existing rather than a permission denial. Fix the server to stay around until it is explicitly killed by the test scripts. This fix then revealed a problem with the last inet_socket test: although the permission denial correctly prevents the server from receiving the datagram message, the client gets no notification of this failure and hangs on its subsequent attempt to read a reply from the server. Add a call to poll() with a timeout so that the client can handle this situation.
---
v3 removes an unused variable from client.c.
tests/inet_socket/client.c | 18 ++++++ tests/inet_socket/server.c | 134 +++++++++++++++++++++++---------------------- tests/unix_socket/server.c | 132 ++++++++++++++++++++++---------------------- 3 files changed, 155 insertions(+), 129 deletions(-)
tests/inet_socket/client.c +18 -0
@@ -10,6 +10,7 @@#include <unistd.h> #include <fcntl.h> #include <errno.h> +#include <poll.h> #include <selinux/selinux.h> void usage (char *progname)
@@ -76,6 +77,23 @@ main(int argc, char **argv)close (sock);exit (1 ); } + +if (type ==SOCK_DGRAM ) { +struct pollfd fds; + + fds.fd = sock; + fds.events =POLLIN ; + result =poll (&fds,1 ,1000 ); +if (result <0 ) { +perror ("poll" ); +close (sock); +exit (1 ); + }else if (result ==0 ) { +fprintf (stderr,"%s: no reply from server\n" , argv[0 ]); +exit (1 ); + } + } + result =read (sock, label,sizeof (label));if (result <0 ) {perror ("read" );
tests/inet_socket/server.c +69 -65
158 lines not on this page · raw message
tests/unix_socket/server.c +68 -64
156 lines not on this page · raw message
Signature · 1 line
2.1.0