diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2001-03-03 06:50:29 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2001-03-03 06:50:29 +0000 |
commit | 5cab98a552d03dd2c7a566504b72afb11b89c84d (patch) | |
tree | d522ff9f2cc2db7e245645da75821e6ef16604d2 /lib | |
parent | e823d2c765133cc0851045eae69fa841c7bae557 (diff) |
plug many memory leaks
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/rpc/auth_none.c | 10 | ||||
-rw-r--r-- | lib/libc/rpc/auth_unix.c | 3 | ||||
-rw-r--r-- | lib/libc/rpc/clnt_perror.c | 8 | ||||
-rw-r--r-- | lib/libc/rpc/clnt_raw.c | 13 | ||||
-rw-r--r-- | lib/libc/rpc/clnt_simple.c | 14 | ||||
-rw-r--r-- | lib/libc/rpc/getrpcent.c | 14 | ||||
-rw-r--r-- | lib/libc/rpc/rpc_callmsg.c | 8 | ||||
-rw-r--r-- | lib/libc/rpc/svc.c | 20 | ||||
-rw-r--r-- | lib/libc/rpc/svc_raw.c | 16 | ||||
-rw-r--r-- | lib/libc/rpc/svc_simple.c | 4 | ||||
-rw-r--r-- | lib/libc/rpc/svc_tcp.c | 16 | ||||
-rw-r--r-- | lib/libc/rpc/svc_udp.c | 15 | ||||
-rw-r--r-- | lib/libc/rpc/xdr_rec.c | 3 |
13 files changed, 94 insertions, 50 deletions
diff --git a/lib/libc/rpc/auth_none.c b/lib/libc/rpc/auth_none.c index 3f95ca5de58..0abbe099871 100644 --- a/lib/libc/rpc/auth_none.c +++ b/lib/libc/rpc/auth_none.c @@ -28,7 +28,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: auth_none.c,v 1.5 2000/08/24 17:03:19 deraadt Exp $"; +static char *rcsid = "$OpenBSD: auth_none.c,v 1.6 2001/03/03 06:50:27 deraadt Exp $"; #endif /* LIBC_SCCS and not lint */ /* @@ -76,10 +76,10 @@ authnone_create() XDR xdr_stream; register XDR *xdrs; - if (ap == 0) { + if (ap == NULL) { ap = (struct authnone_private *)calloc(1, sizeof (*ap)); - if (ap == 0) - return (0); + if (ap == NULL) + return (NULL); authnone_private = ap; } if (!ap->mcnt) { @@ -104,7 +104,7 @@ authnone_marshal(client, xdrs) { register struct authnone_private *ap = authnone_private; - if (ap == 0) + if (ap == NULL) return (0); return ((*xdrs->x_ops->x_putbytes)(xdrs, ap->marshalled_client, ap->mcnt)); diff --git a/lib/libc/rpc/auth_unix.c b/lib/libc/rpc/auth_unix.c index 50ba106ba0d..21620785ec9 100644 --- a/lib/libc/rpc/auth_unix.c +++ b/lib/libc/rpc/auth_unix.c @@ -28,7 +28,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: auth_unix.c,v 1.12 2000/08/24 17:03:20 deraadt Exp $"; +static char *rcsid = "$OpenBSD: auth_unix.c,v 1.13 2001/03/03 06:50:28 deraadt Exp $"; #endif /* LIBC_SCCS and not lint */ /* @@ -119,6 +119,7 @@ authunix_create(machname, uid, gid, len, aup_gids) #ifndef KERNEL if (au == NULL) { (void)fprintf(stderr, "authunix_create: out of memory\n"); + free(auth); return (NULL); } #endif diff --git a/lib/libc/rpc/clnt_perror.c b/lib/libc/rpc/clnt_perror.c index 66cfde0fdab..a341b06af7c 100644 --- a/lib/libc/rpc/clnt_perror.c +++ b/lib/libc/rpc/clnt_perror.c @@ -28,7 +28,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: clnt_perror.c,v 1.10 1998/12/30 22:26:18 deraadt Exp $"; +static char *rcsid = "$OpenBSD: clnt_perror.c,v 1.11 2001/03/03 06:50:28 deraadt Exp $"; #endif /* LIBC_SCCS and not lint */ /* @@ -54,7 +54,7 @@ static char * _buf() { - if (buf == 0) + if (buf == NULL) buf = (char *)malloc(CLNT_PERROR_BUFLEN); return (buf); } @@ -73,7 +73,7 @@ clnt_sperror(rpch, s) char *strstart = str; int ret; - if (str == 0) + if (str == NULL) return (0); CLNT_GETERR(rpch, &e); @@ -208,7 +208,7 @@ clnt_spcreateerror(s) { char *str = _buf(); - if (str == 0) + if (str == NULL) return (0); switch (rpc_createerr.cf_stat) { diff --git a/lib/libc/rpc/clnt_raw.c b/lib/libc/rpc/clnt_raw.c index d6d4c874506..217e3603784 100644 --- a/lib/libc/rpc/clnt_raw.c +++ b/lib/libc/rpc/clnt_raw.c @@ -28,7 +28,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: clnt_raw.c,v 1.8 1998/03/19 00:27:18 millert Exp $"; +static char *rcsid = "$OpenBSD: clnt_raw.c,v 1.9 2001/03/03 06:50:28 deraadt Exp $"; #endif /* LIBC_SCCS and not lint */ /* @@ -90,10 +90,10 @@ clntraw_create(prog, vers) XDR *xdrs = &clp->xdr_stream; CLIENT *client = &clp->client_object; - if (clp == 0) { + if (clp == NULL) { clp = (struct clntraw_private *)calloc(1, sizeof (*clp)); - if (clp == 0) - return (0); + if (clp == NULL) + return (NULL); clntraw_private = clp; } /* @@ -140,7 +140,7 @@ clntraw_call(h, proc, xargs, argsp, xresults, resultsp, timeout) enum clnt_stat status; struct rpc_err error; - if (clp == 0) + if (clp == NULL) return (RPC_FAILED); call_again: /* @@ -221,8 +221,7 @@ clntraw_freeres(cl, xdr_res, res_ptr) register XDR *xdrs = &clp->xdr_stream; bool_t rval; - if (clp == 0) - { + if (clp == NULL) { rval = (bool_t) RPC_FAILED; return (rval); } diff --git a/lib/libc/rpc/clnt_simple.c b/lib/libc/rpc/clnt_simple.c index b3091f293a2..fd4e2fe5a16 100644 --- a/lib/libc/rpc/clnt_simple.c +++ b/lib/libc/rpc/clnt_simple.c @@ -29,7 +29,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: clnt_simple.c,v 1.8 1998/03/19 00:27:20 millert Exp $"; +static char *rcsid = "$OpenBSD: clnt_simple.c,v 1.9 2001/03/03 06:50:28 deraadt Exp $"; #endif /* LIBC_SCCS and not lint */ /* @@ -61,20 +61,26 @@ callrpc(host, prognum, versnum, procnum, inproc, in, outproc, out) xdrproc_t inproc, outproc; char *in, *out; { - register struct callrpc_private *crp = callrpc_private; + struct callrpc_private *save_callrpc_private = callrpc_private; + struct callrpc_private *crp = callrpc_private; struct sockaddr_in server_addr; enum clnt_stat clnt_stat; struct hostent *hp; struct timeval timeout, tottimeout; - if (crp == 0) { + if (crp == NULL) { crp = (struct callrpc_private *)calloc(1, sizeof (*crp)); - if (crp == 0) + if (crp == NULL) return (0); callrpc_private = crp; } if (crp->oldhost == NULL) { crp->oldhost = malloc(MAXHOSTNAMELEN); + if (crp->oldhost == NULL) { + free(crp); + callrpc_private = save_callrpc_private; + return (0); + } crp->oldhost[0] = 0; crp->socket = RPC_ANYSOCK; } diff --git a/lib/libc/rpc/getrpcent.c b/lib/libc/rpc/getrpcent.c index 949304faab8..a1c523aff59 100644 --- a/lib/libc/rpc/getrpcent.c +++ b/lib/libc/rpc/getrpcent.c @@ -29,7 +29,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: getrpcent.c,v 1.8 1997/09/22 05:11:07 millert Exp $"; +static char *rcsid = "$OpenBSD: getrpcent.c,v 1.9 2001/03/03 06:50:28 deraadt Exp $"; #endif /* LIBC_SCCS and not lint */ /* @@ -65,7 +65,7 @@ _rpcdata() { register struct rpcdata *d = rpcdata; - if (d == 0) { + if (d == NULL) { d = (struct rpcdata *)calloc(1, sizeof (struct rpcdata)); rpcdata = d; } @@ -79,7 +79,7 @@ getrpcbynumber(number) register struct rpcdata *d = _rpcdata(); register struct rpcent *p; - if (d == 0) + if (d == NULL) return (0); setrpcent(0); while ((p = getrpcent())) { @@ -117,7 +117,7 @@ setrpcent(f) { register struct rpcdata *d = _rpcdata(); - if (d == 0) + if (d == NULL) return; if (d->rpcf == NULL) d->rpcf = fopen(RPCDB, "r"); @@ -131,7 +131,7 @@ endrpcent() { register struct rpcdata *d = _rpcdata(); - if (d == 0) + if (d == NULL) return; if (d->rpcf && !d->stayopen) { fclose(d->rpcf); @@ -144,7 +144,7 @@ getrpcent() { register struct rpcdata *d = _rpcdata(); - if (d == 0) + if (d == NULL) return(NULL); if (d->rpcf == NULL && (d->rpcf = fopen(RPCDB, "r")) == NULL) return (NULL); @@ -163,7 +163,7 @@ interpret(val, len) char *p; register char *cp, **q; - if (d == 0) + if (d == NULL) return (0); (void) strncpy(d->line, val, BUFSIZ); d->line[BUFSIZ] = '\0'; diff --git a/lib/libc/rpc/rpc_callmsg.c b/lib/libc/rpc/rpc_callmsg.c index 5490ddb7230..69f9dd9cea4 100644 --- a/lib/libc/rpc/rpc_callmsg.c +++ b/lib/libc/rpc/rpc_callmsg.c @@ -28,7 +28,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: rpc_callmsg.c,v 1.5 1999/11/23 22:37:27 deraadt Exp $"; +static char *rcsid = "$OpenBSD: rpc_callmsg.c,v 1.6 2001/03/03 06:50:28 deraadt Exp $"; #endif /* LIBC_SCCS and not lint */ /* @@ -123,7 +123,8 @@ xdr_callmsg(xdrs, cmsg) if (oa->oa_base == NULL) { oa->oa_base = (caddr_t) mem_alloc(oa->oa_length); - /* XXX */ + if (oa->oa_base == NULL) + return (FALSE); } buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length)); if (buf == NULL) { @@ -158,7 +159,8 @@ xdr_callmsg(xdrs, cmsg) if (oa->oa_base == NULL) { oa->oa_base = (caddr_t) mem_alloc(oa->oa_length); - /* XXX */ + if (oa->oa_base == NULL) + return (FALSE); } buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length)); if (buf == NULL) { diff --git a/lib/libc/rpc/svc.c b/lib/libc/rpc/svc.c index 81279156d12..f31f8ce6a06 100644 --- a/lib/libc/rpc/svc.c +++ b/lib/libc/rpc/svc.c @@ -28,7 +28,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: svc.c,v 1.12 1999/11/23 22:37:28 deraadt Exp $"; +static char *rcsid = "$OpenBSD: svc.c,v 1.13 2001/03/03 06:50:28 deraadt Exp $"; #endif /* LIBC_SCCS and not lint */ /* @@ -83,6 +83,17 @@ void xprt_register(xprt) SVCXPRT *xprt; { + /* ignore failure conditions */ + (void) __xprt_register(xprt); +} + +/* + * Activate a transport handle. + */ +int +__xprt_register(xprt) + SVCXPRT *xprt; +{ register int sock = xprt->xp_sock; if (sock+1 > __svc_fdsetsize) { @@ -90,7 +101,8 @@ xprt_register(xprt) fd_set *fds; fds = (fd_set *)malloc(bytes); - /* XXX */ + if (fds == NULL) + return (0); memset(fds, 0, bytes); if (__svc_fdset) { memcpy(fds, __svc_fdset, howmany(__svc_fdsetsize, @@ -112,7 +124,8 @@ xprt_register(xprt) if (sock+1 > size) size = sock+1; xp = (SVCXPRT **)mem_alloc(size * sizeof(SVCXPRT *)); - /* XXX */ + if (xp == NULL) + return (0); memset(xp, 0, size * sizeof(SVCXPRT *)); if (xports) { memcpy(xp, xports, xportssize * sizeof(SVCXPRT *)); @@ -123,6 +136,7 @@ xprt_register(xprt) } xports[sock] = xprt; svc_maxfd = max(svc_maxfd, sock); + return (1); } /* diff --git a/lib/libc/rpc/svc_raw.c b/lib/libc/rpc/svc_raw.c index 512f911399a..c76197d6ac0 100644 --- a/lib/libc/rpc/svc_raw.c +++ b/lib/libc/rpc/svc_raw.c @@ -28,7 +28,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: svc_raw.c,v 1.4 1996/09/15 09:31:39 tholo Exp $"; +static char *rcsid = "$OpenBSD: svc_raw.c,v 1.5 2001/03/03 06:50:28 deraadt Exp $"; #endif /* LIBC_SCCS and not lint */ /* @@ -75,10 +75,10 @@ svcraw_create() { register struct svcraw_private *srp = svcraw_private; - if (srp == 0) { + if (srp == NULL) { srp = (struct svcraw_private *)calloc(1, sizeof (*srp)); - if (srp == 0) - return (0); + if (srp == NULL) + return (NULL); } srp->server.xp_sock = 0; srp->server.xp_port = 0; @@ -104,7 +104,7 @@ svcraw_recv(xprt, msg) register struct svcraw_private *srp = svcraw_private; register XDR *xdrs; - if (srp == 0) + if (srp == NULL) return (0); xdrs = &srp->xdr_stream; xdrs->x_op = XDR_DECODE; @@ -123,7 +123,7 @@ svcraw_reply(xprt, msg) register struct svcraw_private *srp = svcraw_private; register XDR *xdrs; - if (srp == 0) + if (srp == NULL) return (FALSE); xdrs = &srp->xdr_stream; xdrs->x_op = XDR_ENCODE; @@ -143,7 +143,7 @@ svcraw_getargs(xprt, xdr_args, args_ptr) { register struct svcraw_private *srp = svcraw_private; - if (srp == 0) + if (srp == NULL) return (FALSE); return ((*xdr_args)(&srp->xdr_stream, args_ptr)); } @@ -158,7 +158,7 @@ svcraw_freeargs(xprt, xdr_args, args_ptr) register struct svcraw_private *srp = svcraw_private; register XDR *xdrs; - if (srp == 0) + if (srp == NULL) return (FALSE); xdrs = &srp->xdr_stream; xdrs->x_op = XDR_FREE; diff --git a/lib/libc/rpc/svc_simple.c b/lib/libc/rpc/svc_simple.c index 5210321a9c7..6414eb50d50 100644 --- a/lib/libc/rpc/svc_simple.c +++ b/lib/libc/rpc/svc_simple.c @@ -28,7 +28,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: svc_simple.c,v 1.6 1998/11/22 07:38:25 deraadt Exp $"; +static char *rcsid = "$OpenBSD: svc_simple.c,v 1.7 2001/03/03 06:50:28 deraadt Exp $"; #endif /* LIBC_SCCS and not lint */ /* @@ -69,7 +69,7 @@ registerrpc(prognum, versnum, procnum, progname, inproc, outproc) "can't reassign procedure number %u\n", NULLPROC); return (-1); } - if (transp == 0) { + if (transp == NULL) { transp = svcudp_create(RPC_ANYSOCK); if (transp == NULL) { (void) fprintf(stderr, "couldn't create an rpc server\n"); diff --git a/lib/libc/rpc/svc_tcp.c b/lib/libc/rpc/svc_tcp.c index fa1cfcdf1e3..3de72ea6e53 100644 --- a/lib/libc/rpc/svc_tcp.c +++ b/lib/libc/rpc/svc_tcp.c @@ -28,7 +28,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: svc_tcp.c,v 1.18 1998/05/22 04:23:01 deraadt Exp $"; +static char *rcsid = "$OpenBSD: svc_tcp.c,v 1.19 2001/03/03 06:50:28 deraadt Exp $"; #endif /* LIBC_SCCS and not lint */ /* @@ -179,7 +179,13 @@ svctcp_create(sock, sendsize, recvsize) xprt->xp_ops = &svctcp_rendezvous_op; xprt->xp_port = ntohs(addr.sin_port); xprt->xp_sock = sock; - xprt_register(xprt); + if (__xprt_register(xprt) == 0) { + if (madesock) + (void)close(sock); + free(r); + free(xprt); + return (NULL); + } return (xprt); } @@ -228,7 +234,11 @@ makefd_xprt(fd, sendsize, recvsize) xprt->xp_ops = &svctcp_op; /* truely deals with calls */ xprt->xp_port = 0; /* this is a connection, not a rendezvouser */ xprt->xp_sock = fd; - xprt_register(xprt); + if (__xprt_register(xprt) == 0) { + free(xprt); + free(cd); + return (NULL); + } done: return (xprt); } diff --git a/lib/libc/rpc/svc_udp.c b/lib/libc/rpc/svc_udp.c index 00a62796593..9abbc065b81 100644 --- a/lib/libc/rpc/svc_udp.c +++ b/lib/libc/rpc/svc_udp.c @@ -28,7 +28,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: svc_udp.c,v 1.8 1998/03/19 00:27:26 millert Exp $"; +static char *rcsid = "$OpenBSD: svc_udp.c,v 1.9 2001/03/03 06:50:28 deraadt Exp $"; #endif /* LIBC_SCCS and not lint */ /* @@ -157,7 +157,14 @@ svcudp_bufcreate(sock, sendsz, recvsz) xprt->xp_ops = &svcudp_op; xprt->xp_port = ntohs(addr.sin_port); xprt->xp_sock = sock; - xprt_register(xprt); + if (__xprt_register(xprt) == 0) { + if (madesock) + (void)close(sock); + free(xprt); + free(rpc_buffer(xprt)); + free(su); + return (NULL); + } return (xprt); } @@ -371,12 +378,15 @@ svcudp_enablecache(transp, size) uc->uc_entries = ALLOC(cache_ptr, size * SPARSENESS); if (uc->uc_entries == NULL) { CACHE_PERROR("enablecache: could not allocate cache data"); + free(uc); return(0); } BZERO(uc->uc_entries, cache_ptr, size * SPARSENESS); uc->uc_fifo = ALLOC(cache_ptr, size); if (uc->uc_fifo == NULL) { CACHE_PERROR("enablecache: could not allocate cache fifo"); + free(uc->uc_entries); + free(uc); return(0); } BZERO(uc->uc_fifo, cache_ptr, size); @@ -426,6 +436,7 @@ cache_set(xprt, replylen) newbuf = mem_alloc(su->su_iosz); if (newbuf == NULL) { CACHE_PERROR("cache_set: could not allocate new rpc_buffer"); + free(victim); return; } } diff --git a/lib/libc/rpc/xdr_rec.c b/lib/libc/rpc/xdr_rec.c index 68ff3622cbe..ba07613c975 100644 --- a/lib/libc/rpc/xdr_rec.c +++ b/lib/libc/rpc/xdr_rec.c @@ -27,7 +27,7 @@ * Mountain View, California 94043 */ #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: xdr_rec.c,v 1.6 1998/05/20 23:50:02 deraadt Exp $"; +static char *rcsid = "$OpenBSD: xdr_rec.c,v 1.7 2001/03/03 06:50:28 deraadt Exp $"; #endif /* LIBC_SCCS and not lint */ /* @@ -159,6 +159,7 @@ xdrrec_create(xdrs, sendsize, recvsize, tcp_handle, readit, writeit) rstrm->the_buffer = mem_alloc(sendsize + recvsize + BYTES_PER_XDR_UNIT); if (rstrm->the_buffer == NULL) { (void)fprintf(stderr, "xdrrec_create: out of memory\n"); + free(rstrm); return; } for (rstrm->out_base = rstrm->the_buffer; |