diff options
author | Federico G. Schwindt <fgsch@cvs.openbsd.org> | 2002-11-15 10:03:10 +0000 |
---|---|---|
committer | Federico G. Schwindt <fgsch@cvs.openbsd.org> | 2002-11-15 10:03:10 +0000 |
commit | 77500b5209faabc24efa36694f6a0ce1722c3e90 (patch) | |
tree | 697be09bfb665a00b8616470b1a222e5ae0cb5ad /usr.bin | |
parent | be0e0aff0213033461f386d5563ebe54d5a2d784 (diff) |
lseek(2) may return -1 when getting the public/private key lenght.
Simplify the code and check for errors using fstat(2).
Problem reported by Mauricio Sanchez, markus@ ok.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/ssh/authfile.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/usr.bin/ssh/authfile.c b/usr.bin/ssh/authfile.c index 9cdd528442c..33217bf3b68 100644 --- a/usr.bin/ssh/authfile.c +++ b/usr.bin/ssh/authfile.c @@ -36,7 +36,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: authfile.c,v 1.50 2002/06/24 14:55:38 markus Exp $"); +RCSID("$OpenBSD: authfile.c,v 1.51 2002/11/15 10:03:09 fgsch Exp $"); #include <openssl/err.h> #include <openssl/evp.h> @@ -232,12 +232,17 @@ key_load_public_rsa1(int fd, const char *filename, char **commentp) { Buffer buffer; Key *pub; + struct stat st; char *cp; int i; off_t len; - len = lseek(fd, (off_t) 0, SEEK_END); - lseek(fd, (off_t) 0, SEEK_SET); + if (fstat(fd, &st) < 0) { + error("fstat for key file %.200s failed: %.100s", + filename, strerror(errno)); + return NULL; + } + len = st.st_size; buffer_init(&buffer); cp = buffer_append_space(&buffer, len); @@ -318,9 +323,15 @@ key_load_private_rsa1(int fd, const char *filename, const char *passphrase, CipherContext ciphercontext; Cipher *cipher; Key *prv = NULL; + struct stat st; - len = lseek(fd, (off_t) 0, SEEK_END); - lseek(fd, (off_t) 0, SEEK_SET); + if (fstat(fd, &st) < 0) { + error("fstat for key file %.200s failed: %.100s", + filename, strerror(errno)); + close(fd); + return NULL; + } + len = st.st_size; buffer_init(&buffer); cp = buffer_append_space(&buffer, len); |