Skip to content

Commit

Permalink
* nis/nis_callback.c (__nis_create_callback): Use asprinf instead
Browse files Browse the repository at this point in the history
	of snprintf+strdup.  Handle OOM.
	* nis/nis_callback.c (__nis_create_callback): Allocate cb and
	cb->serv together.  Remove now obsolete free calls.
	(__nis_destroy_callback): Remove now obsolete free call.
  • Loading branch information
Ulrich Drepper committed May 18, 2006
1 parent 6e2a782 commit f90de83
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
8 changes: 8 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
2006-05-18 Ulrich Drepper <drepper@redhat.com>

* nis/nis_callback.c (__nis_create_callback): Use asprinf instead
of snprintf+strdup. Handle OOM.
* nis/nis_callback.c (__nis_create_callback): Allocate cb and
cb->serv together. Remove now obsolete free calls.
(__nis_destroy_callback): Remove now obsolete free call.

2006-05-18 David Woodhouse <dwmw2@infradead.org>

* sysdeps/posix/getaddrinfo.c: Add unique labels to the default
Expand Down
26 changes: 10 additions & 16 deletions nis/nis_callback.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 1997, 1998, 1999, 2000, 2005 Free Software Foundation, Inc.
/* Copyright (C) 1997,1998,1999,2000,2005,2006 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1997.
Expand Down Expand Up @@ -275,15 +275,13 @@ __nis_create_callback (int (*callback) (const_nis_name, const nis_object *,
int sock = RPC_ANYSOCK;
struct sockaddr_in sin;
socklen_t len = sizeof (struct sockaddr_in);
char addr[NIS_MAXNAMELEN + 1];
unsigned short port;

cb = (struct nis_cb *) calloc (1, sizeof (struct nis_cb));
cb = (struct nis_cb *) calloc (1,
sizeof (struct nis_cb) + sizeof (nis_server));
if (__builtin_expect (cb == NULL, 0))
goto failed;
cb->serv = (nis_server *) calloc (1, sizeof (nis_server));
if (__builtin_expect (cb->serv == NULL, 0))
goto failed;
cb->serv = (nis_server *) (cb + 1);
cb->serv->name = strdup (nis_local_principal ());
if (__builtin_expect (cb->serv->name == NULL, 0))
goto failed;
Expand Down Expand Up @@ -334,7 +332,6 @@ __nis_create_callback (int (*callback) (const_nis_name, const nis_object *,
xprt_unregister (cb->xprt);
svc_destroy (cb->xprt);
xdr_free ((xdrproc_t) _xdr_nis_server, (char *) cb->serv);
free (cb->serv);
free (cb);
syslog (LOG_ERR, "NIS+: failed to register callback dispatcher");
return NULL;
Expand All @@ -345,27 +342,25 @@ __nis_create_callback (int (*callback) (const_nis_name, const nis_object *,
xprt_unregister (cb->xprt);
svc_destroy (cb->xprt);
xdr_free ((xdrproc_t) _xdr_nis_server, (char *) cb->serv);
free (cb->serv);
free (cb);
syslog (LOG_ERR, "NIS+: failed to read local socket info");
return NULL;
}
port = ntohs (sin.sin_port);
get_myaddress (&sin);
snprintf (addr, sizeof (addr), "%s.%d.%d", inet_ntoa (sin.sin_addr),
(port & 0xFF00) >> 8, port & 0x00FF);
cb->serv->ep.ep_val[0].uaddr = strdup (addr);

if (asprintf (&cb->serv->ep.ep_val[0].uaddr, "%s.%d.%d",
inet_ntoa (sin.sin_addr), (port & 0xFF00) >> 8, port & 0x00FF)
< 0)
goto failed;

return cb;

failed:
if (cb)
{
if (cb->serv)
{
xdr_free ((xdrproc_t) _xdr_nis_server, (char *) cb->serv);
free (cb->serv);
}
xdr_free ((xdrproc_t) _xdr_nis_server, (char *) cb->serv);
free (cb);
}
syslog (LOG_ERR, "NIS+: out of memory allocating callback");
Expand All @@ -379,7 +374,6 @@ __nis_destroy_callback (struct nis_cb *cb)
svc_destroy (cb->xprt);
close (cb->sock);
xdr_free ((xdrproc_t) _xdr_nis_server, (char *) cb->serv);
free (cb->serv);
free (cb);

return NIS_SUCCESS;
Expand Down

0 comments on commit f90de83

Please sign in to comment.