summary refs log tree commit diff
path: root/crypt
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>2004-06-10 02:16:08 +0000
committerRoland McGrath <roland@gnu.org>2004-06-10 02:16:08 +0000
commitf05a089da96014435cce5c9f17f386ba846a1a6e (patch)
treec1c015aec613464b5050d96889e72092c6622584 /crypt
parente17f8b6119eb64d126422eda8a18d577cbdc9976 (diff)
downloadglibc-f05a089da96014435cce5c9f17f386ba846a1a6e.tar.gz
glibc-f05a089da96014435cce5c9f17f386ba846a1a6e.tar.xz
glibc-f05a089da96014435cce5c9f17f386ba846a1a6e.zip
[BZ #199]
2004-06-08  Jakub Jelinek  <jakub@redhat.com>
	[BZ #199]
	* crypt/md5-crypt.c (__md5_crypt): Only update buflen if realloc
	succeeds.  Reported by Miles Ohlrich <miles@cray.com>.

	* elf/chroot_canon.c (chroot_canon): Avoid segfault if first malloc
	fails.  Avoid memory leak if realloc fails.
Diffstat (limited to 'crypt')
-rw-r--r--crypt/md5-crypt.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/crypt/md5-crypt.c b/crypt/md5-crypt.c
index ededfaec71..7ba1491db6 100644
--- a/crypt/md5-crypt.c
+++ b/crypt/md5-crypt.c
@@ -1,6 +1,7 @@
 /* One way encryption based on MD5 sum.
    Compatible with the behavior of MD5 crypt introduced in FreeBSD 2.0.
-   Copyright (C) 1996,1997,1999,2000,2001,2002 Free Software Foundation, Inc.
+   Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002, 2004
+   Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
 
@@ -250,15 +251,12 @@ __md5_crypt (const char *key, const char *salt)
 
   if (buflen < needed)
     {
-      char *new_buffer;
-
-      buflen = needed;
-
-      new_buffer = (char *) realloc (buffer, buflen);
+      char *new_buffer = (char *) realloc (buffer, needed);
       if (new_buffer == NULL)
 	return NULL;
 
       buffer = new_buffer;
+      buflen = needed;
     }
 
   return __md5_crypt_r (key, salt, buffer, buflen);