gnu: Add kafs-client
[jackhill/guix/guix.git] / gnu / packages / patches / libtirpc-hurd-client.patch
1 Taken from https://salsa.debian.org/debian/libtirpc/-/raw/master/debian/patches/06-hurd-client-port.diff
2
3 Description: Fix client code for hurd, avoiding malloc overflow
4 When trying to setup a inet connection, it happens the following:
5 - in libtirp, src/clnt_vc.c, clnt_vc_create gets called
6 - when trying to allocate vc_fd_locks, __rpc_dtbsize() is used as size
7 for that array of fd locks
8 - __rpc_dtbsize(), in src/rpc_generic.c, queries using rlimit the
9 maximum (rlim_max) number of file descriptors (RLIMIT_NOFILE):
10 - on Linux, the default is { rlim_cur = 1024, rlim_max = 4096 }
11 - on kFreeBSD, the default is { rlim_cur = 1024, rlim_max = 1024 }
12 - on Hurd, the default is { rlim_cur = 1024, rlim_max = RLIM_INFINITY }
13 meaning that on Hurd the memory allocation fails (as
14 __rpc_dtbsize() * sizeof(int) overflows and is negative)
15
16 Change libtiprc so __rpc_dtbsize falls back on rlim_cur if rlim_max
17 is unlimited.
18
19 This patch fixes the client connection using inet sockets; local unix
20 sockets are not working, for two reasons so far:
21 - getpeername on them gives EOPNOTSUPP
22 - SO_REUSEADDR is not implemented for them
23 Author: Pino Toscano <pino@debian.org>
24
25 Bug-Debian: http://bugs.debian.org/739674
26 Forwarded: no
27 Reviewed-By: Petter Reinholdtsen
28 Last-Update: 2014-03-03
29
30 --- a/src/rpc_generic.c
31 +++ b/src/rpc_generic.c
32 @@ -107,12 +107,17 @@
33 {
34 static int tbsize;
35 struct rlimit rl;
36 + rlim_t lim;
37
38 if (tbsize) {
39 return (tbsize);
40 }
41 if (getrlimit(RLIMIT_NOFILE, &rl) == 0) {
42 - return (tbsize = (int)rl.rlim_max);
43 + lim = rl.rlim_max;
44 + if (lim == RLIM_INFINITY) {
45 + lim = rl.rlim_cur;
46 + }
47 + return (tbsize = (int)lim);
48 }
49 /*
50 * Something wrong. I'll try to save face by returning a