aboutsummaryrefslogtreecommitdiff
path: root/nis/nis_subr.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2004-05-07 03:57:57 +0000
committerUlrich Drepper <drepper@redhat.com>2004-05-07 03:57:57 +0000
commit9be31a514921c7415d61834ffa1387f24f631dfb (patch)
treee6d77813cd31858a49c7315b98510e3e3fc06c13 /nis/nis_subr.c
parentf1debaf68214cb898f67355ee83169cc135e14e9 (diff)
downloadglibc-9be31a514921c7415d61834ffa1387f24f631dfb.tar
glibc-9be31a514921c7415d61834ffa1387f24f631dfb.tar.gz
glibc-9be31a514921c7415d61834ffa1387f24f631dfb.tar.bz2
glibc-9be31a514921c7415d61834ffa1387f24f631dfb.zip
Update.
* sysdeps/unix/sysv/linux/ifreq.c (__ifreq): Fix memory handling. * sysdeps/generic/ifreq.c (__ifreq): Fix memory handling. * resolv/res_hconf.c (_res_hconf_reorder_addrs): Make clear that realloc cannot fail. * nss/nss_files/files-netgrp.c (EXPAND): Free buffer which cannot be expanded. * nis/nis_table.c: Clean up memory handling. * nis/nis_subr.c (nis_getnames): Clean up memory handling. * nis/nis_removemember.c (nis_removemember): Add comment explaining use of realloc.
Diffstat (limited to 'nis/nis_subr.c')
-rw-r--r--nis/nis_subr.c41
1 files changed, 26 insertions, 15 deletions
diff --git a/nis/nis_subr.c b/nis/nis_subr.c
index 47a22e38c1..78e58aeba9 100644
--- a/nis/nis_subr.c
+++ b/nis/nis_subr.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 1997, 1999, 2000 Free Software Foundation, Inc.
+/* Copyright (c) 1997, 1999, 2000, 2004 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
@@ -117,8 +117,11 @@ nis_getnames (const_nis_name name)
{
nis_name *getnames = NULL;
char local_domain[NIS_MAXNAMELEN + 1];
- char *path, *cp;
- int count, pos, have_point;
+ char *path;
+ char *cp;
+ int count;
+ int pos = 0;
+ int have_point;
char *saveptr;
strncpy (local_domain, nis_local_directory (), NIS_MAXNAMELEN);
@@ -133,7 +136,13 @@ nis_getnames (const_nis_name name)
if (name[strlen (name) - 1] == '.')
{
if ((getnames[0] = strdup (name)) == NULL)
- return NULL;
+ {
+ free_null:
+ while (pos-- > 0)
+ free (getnames[pos]);
+ free (getnames);
+ return NULL;
+ }
getnames[1] = NULL;
@@ -149,8 +158,6 @@ nis_getnames (const_nis_name name)
have_point = (strchr (name, '.') != NULL);
- pos = 0;
-
cp = __strtok_r (path, ":", &saveptr);
while (cp)
{
@@ -164,14 +171,16 @@ nis_getnames (const_nis_name name)
if (pos >= count)
{
count += 5;
- getnames = realloc (getnames, (count + 1) * sizeof (char *));
- if (__builtin_expect (getnames == NULL, 0))
- return NULL;
+ nis_name *newp = realloc (getnames,
+ (count + 1) * sizeof (char *));
+ if (__builtin_expect (newp == NULL, 0))
+ goto free_null;
+ getnames = newp;
}
tmp = malloc (strlen (cptr) + strlen (local_domain) +
strlen (name) + 2);
if (__builtin_expect (tmp == NULL, 0))
- return NULL;
+ goto free_null;
getnames[pos] = tmp;
tmp = stpcpy (tmp, name);
@@ -201,7 +210,7 @@ nis_getnames (const_nis_name name)
tmp = malloc (cplen + strlen (local_domain) + strlen (name) + 2);
if (__builtin_expect (tmp == NULL, 0))
- return NULL;
+ goto free_null;
p = __stpcpy (tmp, name);
*p++ = '.';
@@ -217,7 +226,7 @@ nis_getnames (const_nis_name name)
tmp = malloc (cplen + strlen (name) + 2);
if (__builtin_expect (tmp == NULL, 0))
- return NULL;
+ goto free_null;
p = __stpcpy (tmp, name);
*p++ = '.';
@@ -227,9 +236,11 @@ nis_getnames (const_nis_name name)
if (pos >= count)
{
count += 5;
- getnames = realloc (getnames, (count + 1) * sizeof (char *));
- if (__builtin_expect (getnames == NULL, 0))
- return NULL;
+ nis_name *newp = realloc (getnames,
+ (count + 1) * sizeof (char *));
+ if (__builtin_expect (newp == NULL, 0))
+ goto free_null;
+ getnames = newp;
}
getnames[pos] = tmp;
++pos;