cstp_send_file: use system calls instead of libc for open/read

That simplifies the handling of seccomp rules.
This commit is contained in:
Nikos Mavrogiannopoulos
2015-11-11 15:58:20 +01:00
parent 3ba4c2b618
commit b5640d61fb
2 changed files with 7 additions and 7 deletions

View File

@@ -112,23 +112,24 @@ ssize_t cstp_send(worker_st *ws, const void *data,
ssize_t cstp_send_file(worker_st *ws, const char *file)
{
FILE* fp;
int fd;
char buf[512];
ssize_t len, total = 0;
int ret;
fp = fopen(file, "r");
if (fp == NULL)
fd = open(file, O_RDONLY);
if (fd == -1)
return GNUTLS_E_FILE_ERROR;
while ( (len = fread( buf, 1, sizeof(buf), fp)) > 0) {
while ( (len = read( fd, buf, sizeof(buf))) > 0 ||
(len == -1 && (errno == EINTR || errno == EAGAIN))) {
ret = cstp_send(ws, buf, len);
FATAL_ERR(ws, ret);
total += ret;
}
fclose(fp);
close(fd);
return total;
}

View File

@@ -102,8 +102,7 @@ int disable_system_calls(struct worker_st *ws)
/* we need to open files when we have an xml_config_file setup */
if (ws->config->xml_config_file) {
ADD_SYSCALL(fstat, 0);
ADD_SYSCALL(lseek, 0);
ADD_SYSCALL(stat, 0);
ADD_SYSCALL(open, 0);
}