Skip to content

Commit

Permalink
prevent infinite recursions in echoandcheck SyWriteandcheck in cases …
Browse files Browse the repository at this point in the history
…where the

default stdio output streams cannot be written to
  • Loading branch information
embray authored and ChrisJefferson committed Jan 8, 2019
1 parent ea00cc2 commit 48b871b
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/sysfiles.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,24 @@ ssize_t echoandcheck(int fid, const char *buf, size_t count) {
int ret;
if (syBuf[fid].type == gzip_socket) {
ret = gzwrite(syBuf[fid].gzfp, buf, count);
if (ret < 0)
if (ret < 0) {
ErrorQuit(
"Could not write to compressed file, see 'LastSystemError();'\n",
0L, 0L);
}
}
else {
ret = write(syBuf[fid].echo, buf, count);
if (ret < 0)
ErrorQuit("Could not write to file descriptor %d, see "
"'LastSystemError();'\n",
syBuf[fid].fp, 0L);
if (ret < 0) {
if (syBuf[fid].fp == fileno(stdout) || syBuf[fid].fp == fileno(stderr)) {
Panic("Could not write to stdout/stderr.");
} else {
ErrorQuit("Could not write to file descriptor %d, see "
"'LastSystemError();'\n",
syBuf[fid].fp, 0L);
}
}
}

return ret;
}

Expand Down Expand Up @@ -1539,17 +1544,23 @@ static ssize_t SyWriteandcheck(Int fid, const void * buf, size_t count)
int ret;
if (syBuf[fid].type == gzip_socket) {
ret = gzwrite(syBuf[fid].gzfp, buf, count);
if (ret < 0)
if (ret < 0) {
ErrorQuit(
"Cannot write to compressed file, see 'LastSystemError();'\n",
0L, 0L);
}
}
else {
ret = write(syBuf[fid].fp, buf, count);
if (ret < 0)
ErrorQuit("Cannot write to file descriptor %d, see "
"'LastSystemError();'\n",
syBuf[fid].fp, 0L);
if (ret < 0) {
if (syBuf[fid].fp == fileno(stdout) || syBuf[fid].fp == fileno(stderr)) {
Panic("Could not write to stdout/stderr.");
} else {
ErrorQuit("Cannot write to file descriptor %d, see "
"'LastSystemError();'\n",
syBuf[fid].fp, 0L);
}
}
}

return ret;
Expand Down

0 comments on commit 48b871b

Please sign in to comment.