summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMatt Johnston <matt@ucc.asn.au>2006-08-20 12:16:13 +0000
committerMatt Johnston <matt@ucc.asn.au>2006-08-20 12:16:13 +0000
commit14a790891fe6179e1577213978264f84cd428c75 (patch)
treef3105db4f8fda1bb653705b5bb6485aef84b6f02
parentd1daf6531a78f9875a8a96114c8d698c600fe5b7 (diff)
Handle failure reading a file (such as a key file)
--HG-- extra : convert_revision : 3219ab5642c86615c6ffb30eb93f573a73415d2f
-rw-r--r--dbutil.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/dbutil.c b/dbutil.c
index 9f4e8b7..52d9008 100644
--- a/dbutil.c
+++ b/dbutil.c
@@ -527,26 +527,36 @@ char * stripcontrol(const char * text) {
* Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */
int buf_readfile(buffer* buf, const char* filename) {
- int fd;
+ int fd = -1;
int len;
int maxlen;
+ ret = DROPBEAR_FAILURE;
fd = open(filename, O_RDONLY);
if (fd < 0) {
- close(fd);
- return DROPBEAR_FAILURE;
+ goto out;
}
do {
maxlen = buf->size - buf->pos;
- len = read(fd, buf_getwriteptr(buf, maxlen),
- maxlen);
+ len = read(fd, buf_getwriteptr(buf, maxlen), maxlen);
+ if (len < 0) {
+ if (errno == EINTR || errno == EAGAIN) {
+ continue;
+ }
+ goto out;
+ }
buf_incrwritepos(buf, len);
} while (len < maxlen && len > 0);
- close(fd);
- return DROPBEAR_SUCCESS;
+ ret = DROPBEAR_SUCCESS;
+
+out:
+ if (fd >= 0) {
+ m_close(fd);
+ }
+ return ret;
}
/* get a line from the file into buffer in the style expected for an