Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prevent infinite recursions in echoandcheck and SyWriteandcheck #3102

Merged
merged 1 commit into from
Jan 8, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions src/sysfiles.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,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 @@ -1540,17 +1545,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