Handle failure reading a file (such as a key file)

--HG--
extra : convert_revision : 3219ab5642c86615c6ffb30eb93f573a73415d2f
This commit is contained in:
Matt Johnston 2006-08-20 12:16:13 +00:00
parent d1daf6531a
commit 14a790891f

View File

@ -527,26 +527,36 @@ char * stripcontrol(const char * text) {
* Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */ * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */
int buf_readfile(buffer* buf, const char* filename) { int buf_readfile(buffer* buf, const char* filename) {
int fd; int fd = -1;
int len; int len;
int maxlen; int maxlen;
ret = DROPBEAR_FAILURE;
fd = open(filename, O_RDONLY); fd = open(filename, O_RDONLY);
if (fd < 0) { if (fd < 0) {
close(fd); goto out;
return DROPBEAR_FAILURE;
} }
do { do {
maxlen = buf->size - buf->pos; maxlen = buf->size - buf->pos;
len = read(fd, buf_getwriteptr(buf, maxlen), len = read(fd, buf_getwriteptr(buf, maxlen), maxlen);
maxlen); if (len < 0) {
if (errno == EINTR || errno == EAGAIN) {
continue;
}
goto out;
}
buf_incrwritepos(buf, len); buf_incrwritepos(buf, len);
} while (len < maxlen && len > 0); } while (len < maxlen && len > 0);
close(fd); ret = DROPBEAR_SUCCESS;
return 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 /* get a line from the file into buffer in the style expected for an