From f90de83143e5c0b9ba049323493a6fd5112e9991 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Thu, 18 May 2006 17:32:19 +0000 Subject: * 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. --- nis/nis_callback.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'nis') diff --git a/nis/nis_callback.c b/nis/nis_callback.c index 7d1b9f8..86d2a5f 100644 --- a/nis/nis_callback.c +++ b/nis/nis_callback.c @@ -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 , 1997. @@ -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; @@ -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; @@ -345,16 +342,17 @@ __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; @@ -362,10 +360,7 @@ __nis_create_callback (int (*callback) (const_nis_name, const nis_object *, 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"); @@ -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; -- cgit v1.1