diff options
author | Ulrich Drepper <drepper@redhat.com> | 1999-05-16 10:14:25 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 1999-05-16 10:14:25 +0000 |
commit | 32abdb710c9335481da780eab5ad790318d2fadf (patch) | |
tree | 70c94809f5ec43a895c614a445a32f4d18d925c5 /nis/nis_subr.c | |
parent | 7d853c902b9f79a32c8c1921b16107648c15f0e3 (diff) | |
download | glibc-32abdb710c9335481da780eab5ad790318d2fadf.tar.gz glibc-32abdb710c9335481da780eab5ad790318d2fadf.tar.xz glibc-32abdb710c9335481da780eab5ad790318d2fadf.zip |
Update.
1999-05-16 Thorsten Kukuk <kukuk@suse.de> * sunrpc/etc.rpc: Add portmapper, rstat_svc and pcnfs. * sunrpc/key_call.c: Fix memory leak, close file handle. * nis/nis_creategroup.c: Use malloc instead of calloc, set ctime and mtime. * nis/nis_subr.c: Check for realloc result. * nis/nis_file.c: Fix memory leak. * nis/nis_table.c: Pretty print. * nis/nis_getservlist.c: Likewise. * nis/nis_ismember.c: Likewise. * nis/nis_lookup.c: Likewise. * nis/nis_ping.c: Likewise. * nis/nis_removemember.c: Likewise. * nis/nis_util.c: Likewise, check calloc result.
Diffstat (limited to 'nis/nis_subr.c')
-rw-r--r-- | nis/nis_subr.c | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/nis/nis_subr.c b/nis/nis_subr.c index 3283e4cf93..c7d58a60e9 100644 --- a/nis/nis_subr.c +++ b/nis/nis_subr.c @@ -1,4 +1,4 @@ -/* Copyright (c) 1997 Free Software Foundation, Inc. +/* Copyright (c) 1997, 1999 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997. @@ -52,8 +52,8 @@ nis_leaf_of_r (const_nis_name name, char *buffer, size_t buflen) errno = ERANGE; return NULL; } - strncpy (buffer, name, i); - buffer[i] = 0; + + *((char *) __mempcpy (buffer, name, i)) = '\0'; } return buffer; @@ -87,8 +87,8 @@ nis_name_of_r (const_nis_name name, char *buffer, size_t buflen) errno = ERANGE; return NULL; } - memcpy (buffer, name, diff - 1); - buffer[diff - 1] = '\0'; + + *((char *) __mempcpy (buffer, name, diff - 1)) = '\0'; if (diff - 1 == 0) return NULL; @@ -109,6 +109,9 @@ count_dots (const_nis_name str) return count; } +/* If we run out of memory, we don't give already allocated memory + free. The overhead for bringing getnames back in a safe state to + free it is to big. */ nis_name * nis_getnames (const_nis_name name) { @@ -116,22 +119,22 @@ nis_getnames (const_nis_name name) char local_domain[NIS_MAXNAMELEN + 1]; char *path, *cp; int count, pos, have_point; + char *saveptr; strncpy (local_domain, nis_local_directory (), NIS_MAXNAMELEN); local_domain[NIS_MAXNAMELEN] = '\0'; count = 1; - if ((getnames = malloc ((count + 1) * sizeof (char *))) == NULL) + getnames = malloc ((count + 1) * sizeof (char *)); + if (getnames == NULL) return NULL; /* Do we have a fully qualified NIS+ name ? If yes, give it back */ if (name[strlen (name) - 1] == '.') { if ((getnames[0] = strdup (name)) == NULL) - { - free (getnames); - return NULL; - } + return NULL; + getnames[1] = NULL; return getnames; @@ -148,7 +151,7 @@ nis_getnames (const_nis_name name) pos = 0; - cp = strtok (path, ":"); + cp = __strtok_r (path, ":", &saveptr); while (cp) { if (strcmp (cp, "$") == 0) @@ -162,6 +165,8 @@ nis_getnames (const_nis_name name) { count += 5; getnames = realloc (getnames, (count + 1) * sizeof (char *)); + if (getnames == NULL) + return NULL; } tmp = malloc (strlen (cptr) + strlen (local_domain) + strlen (name) + 2); @@ -188,35 +193,35 @@ nis_getnames (const_nis_name name) else { char *tmp; + size_t cplen = strlen (cp); - if (cp[strlen (cp) - 1] == '$') + if (cp[cplen - 1] == '$') { char *p; - tmp = malloc (strlen (cp) + strlen (local_domain) + - strlen (name) + 2); + tmp = malloc (cplen + strlen (local_domain) + strlen (name) + 2); if (tmp == NULL) return NULL; - p = stpcpy (tmp, name); + p = __stpcpy (tmp, name); *p++ = '.'; - p = stpcpy (p, cp); + p = __mempcpy (p, cp, cplen); --p; if (p[-1] != '.') *p++ = '.'; - stpcpy (p, local_domain); + __stpcpy (p, local_domain); } else { char *p; - tmp = malloc (strlen (cp) + strlen (name) + 2); + tmp = malloc (cplen + strlen (name) + 2); if (tmp == NULL) return NULL; - p = stpcpy (tmp, name); + p = __stpcpy (tmp, name); *p++ = '.'; - stpcpy (p, cp); + memcpy (p, cp, cplen + 1); } if (pos >= count) @@ -229,7 +234,7 @@ nis_getnames (const_nis_name name) getnames[pos] = tmp; ++pos; } - cp = strtok (NULL, ":"); + cp = __strtok_r (NULL, ":", &saveptr); } getnames[pos] = NULL; |