]> git.ipfire.org Git - thirdparty/glibc.git/blame - sunrpc/tst-udp-error.c
Update copyright dates with scripts/update-copyrights
[thirdparty/glibc.git] / sunrpc / tst-udp-error.c
CommitLineData
d42eed4a 1/* Check for use-after-free in clntudp_call (bug 21115).
2b778ceb 2 Copyright (C) 2017-2021 Free Software Foundation, Inc.
d42eed4a
FW
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
5a82c748 17 <https://www.gnu.org/licenses/>. */
d42eed4a
FW
18
19#include <netinet/in.h>
20#include <rpc/clnt.h>
21#include <rpc/svc.h>
22#include <support/check.h>
23#include <support/namespace.h>
24#include <support/xsocket.h>
25#include <unistd.h>
26
27static int
28do_test (void)
29{
30 support_become_root ();
31 support_enter_network_namespace ();
32
33 /* Obtain a likely-unused port number. */
34 struct sockaddr_in sin =
35 {
36 .sin_family = AF_INET,
37 .sin_addr.s_addr = htonl (INADDR_LOOPBACK),
38 };
39 {
40 int fd = xsocket (AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
41 xbind (fd, (struct sockaddr *) &sin, sizeof (sin));
42 socklen_t sinlen = sizeof (sin);
43 xgetsockname (fd, (struct sockaddr *) &sin, &sinlen);
44 /* Close the socket, so that we will receive an error below. */
45 close (fd);
46 }
47
48 int sock = RPC_ANYSOCK;
49 CLIENT *clnt = clntudp_create
50 (&sin, 1, 2, (struct timeval) { 1, 0 }, &sock);
51 TEST_VERIFY_EXIT (clnt != NULL);
52 TEST_VERIFY (clnt_call (clnt, 3,
53 (xdrproc_t) xdr_void, NULL,
54 (xdrproc_t) xdr_void, NULL,
55 ((struct timeval) { 3, 0 }))
56 == RPC_CANTRECV);
57 clnt_destroy (clnt);
58
59 return 0;
60}
61
62#include <support/test-driver.c>