From 6af75bb33b8cf1e2bbc214d1723113c9e7c8f301 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Love=20H=C3=B6rnquist=20=C3=85strand?= Date: Mon, 6 Sep 2004 06:45:12 +0000 Subject: [PATCH] (seed_something): avoid poking at memory that is uninitialized, make valgrind unhappy. Pointd out by abartlet@samba.org. While where, plug the fd leak. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@14193 ec53bebd-3082-4978-b11e-865c3cabbd6b --- lib/krb5/crypto.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/krb5/crypto.c b/lib/krb5/crypto.c index b6fe5749b..9b3be1d2b 100644 --- a/lib/krb5/crypto.c +++ b/lib/krb5/crypto.c @@ -3723,17 +3723,19 @@ krb5_decrypt_EncryptedData(krb5_context context, static int seed_something(void) { - int fd = -1; char buf[1024], seedfile[256]; /* If there is a seed file, load it. But such a file cannot be trusted, so use 0 for the entropy estimate */ if (RAND_file_name(seedfile, sizeof(seedfile))) { + int fd; fd = open(seedfile, O_RDONLY); if (fd >= 0) { - read(fd, buf, sizeof(buf)); - /* Use the full buffer anyway */ - RAND_add(buf, sizeof(buf), 0.0); + ssize_t ret; + ret = read(fd, buf, sizeof(buf)); + if (ret > 0) + RAND_add(buf, ret, 0.0); + close(fd); } else seedfile[0] = '\0'; } else