nightmaremail

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit a524a360927f79dd29d2c56b46892828eb79a5fa
parent 3fb8d27d07565d86ee45d4bb4d7a3fa4a94f3176
Author: Rolf Eike Beer <eike@sf-mail.de>
Date:   Mon, 15 Jun 2020 20:21:04 +0200

improve checks for return value of read() and write() and it's wrappers

From the OpenBSD man page of read()

  ...some platforms allow for nbytes to range between SSIZE_MAX and
  SIZE_MAX - 2, in which case the return value of an error-free read() may
  appear as a negative number distinct from -1.

Diffstat:
Mqmail-pop3d.c | 4++--
Mqmail-popup.c | 4++--
Mqmail-qmqpc.c | 4++--
Mqmail-qmqpd.c | 4++--
Mqmail-qmtpd.c | 4++--
Mqmail-remote.c | 4++--
Mqmail-send.c | 4++--
Mqmail-smtpd.c | 4++--
Mslurpclose.c | 2+-
Msubstdi.c | 5+++--
Mtcpto.c | 2+-
11 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/qmail-pop3d.c b/qmail-pop3d.c @@ -28,7 +28,7 @@ ssize_t saferead(int fd, void *buf, size_t len) { ssize_t r; r = timeoutread(1200,fd,buf,len); - if (r <= 0) die(); + if (r == 0 || r == -1) die(); return r; } @@ -36,7 +36,7 @@ ssize_t safewrite(int fd, const void *buf, size_t len) { ssize_t r; r = timeoutwrite(1200,fd,buf,len); - if (r <= 0) die(); + if (r == 0 || r == -1) die(); return r; } diff --git a/qmail-popup.c b/qmail-popup.c @@ -20,7 +20,7 @@ ssize_t saferead(int fd, void *buf, size_t len) { ssize_t r; r = timeoutread(1200,fd,buf,len); - if (r <= 0) die(); + if (r == 0 || r == -1) die(); return r; } @@ -28,7 +28,7 @@ ssize_t safewrite(int fd, const void *buf, size_t len) { ssize_t r; r = timeoutwrite(1200,fd,buf,len); - if (r <= 0) die(); + if (r == 0 || r == -1) die(); return r; } diff --git a/qmail-qmqpc.c b/qmail-qmqpc.c @@ -38,14 +38,14 @@ ssize_t saferead(int fd, void *buf, size_t len) { ssize_t r; r = timeoutread(60,qmqpfd,buf,len); - if (r <= 0) die_conn(); + if (r == 0 || r == -1) die_conn(); return r; } ssize_t safewrite(int fd, const void *buf, size_t len) { ssize_t r; r = timeoutwrite(60,qmqpfd,buf,len); - if (r <= 0) die_conn(); + if (r == 0 || r == -1) die_conn(); return r; } diff --git a/qmail-qmqpd.c b/qmail-qmqpd.c @@ -17,14 +17,14 @@ ssize_t safewrite(int fd, const void *buf, size_t len) { ssize_t r; r = write(fd,buf,len); - if (r <= 0) _exit(0); + if (r == 0 || r == -1) _exit(0); return r; } ssize_t saferead(int fd, void *buf, size_t len) { ssize_t r; r = read(fd,buf,len); - if (r <= 0) _exit(0); + if (r == 0 || r == -1) _exit(0); return r; } diff --git a/qmail-qmtpd.c b/qmail-qmtpd.c @@ -21,7 +21,7 @@ ssize_t safewrite(int fd, const void *buf, size_t len) { ssize_t r; r = write(fd,buf,len); - if (r <= 0) _exit(0); + if (r == 0 || r == -1) _exit(0); return r; } @@ -33,7 +33,7 @@ ssize_t saferead(int fd, void *buf, size_t len) ssize_t r; substdio_flush(&ssout); r = read(fd,buf,len); - if (r <= 0) _exit(0); + if (r == 0 || r == -1) _exit(0); return r; } diff --git a/qmail-remote.c b/qmail-remote.c @@ -110,7 +110,7 @@ ssize_t saferead(int fd, void *buf, size_t len) { ssize_t r; r = timeoutread(timeout,smtpfd,buf,len); - if (r <= 0) dropped(); + if (r == 0 || r == -1) dropped(); return r; } @@ -118,7 +118,7 @@ ssize_t safewrite(int fd, const void *buf, size_t len) { ssize_t r; r = timeoutwrite(timeout,smtpfd,buf,len); - if (r <= 0) dropped(); + if (r == 0 || r == -1) dropped(); return r; } diff --git a/qmail-send.c b/qmail-send.c @@ -298,7 +298,7 @@ fd_set *wfds; int len; len = comm_buf[c].len; w = write(chanfdout[c],comm_buf[c].s + comm_pos[c],len - comm_pos[c]); - if (w <= 0) + if (w == 0 || w == -1) { if ((w == -1) && (errno == error_pipe)) spawndied(c); @@ -632,7 +632,7 @@ char *report; while (pos < bouncetext.len) { w = write(fd,bouncetext.s + pos,bouncetext.len - pos); - if (w <= 0) + if (w == 0 || w == -1) { log1("alert: unable to append to bounce message; HELP! sleeping...\n"); sleep(10); diff --git a/qmail-smtpd.c b/qmail-smtpd.c @@ -33,7 +33,7 @@ ssize_t safewrite(int fd, const void *buf, size_t len) { ssize_t r; r = timeoutwrite(timeout,fd,buf,len); - if (r <= 0) _exit(1); + if (r == 0 || r == -1) _exit(1); return r; } @@ -272,7 +272,7 @@ ssize_t saferead(int fd, void *buf, size_t len) flush(); r = timeoutread(timeout,fd,buf,len); if (r == -1) if (errno == error_timeout) die_alarm(); - if (r <= 0) die_read(); + if (r == 0 || r == -1) die_read(); return r; } diff --git a/slurpclose.c b/slurpclose.c @@ -13,7 +13,7 @@ int bufsize; if (!stralloc_readyplus(sa,bufsize)) { close(fd); return -1; } r = read(fd,sa->s + sa->len,bufsize); if (r == -1) if (errno == error_intr) continue; - if (r <= 0) { close(fd); return r; } + if (r == 0 || r == -1) { close(fd); return r; } sa->len += r; } } diff --git a/substdi.c b/substdi.c @@ -35,7 +35,7 @@ ssize_t substdio_feed(substdio *s) if (s->p) return s->p; q = s->n; r = oneread(s->op,s->fd,s->x,q); - if (r <= 0) return r; + if (r == 0 || r == -1) return r; s->p = r; q -= r; s->n = q; @@ -49,7 +49,8 @@ ssize_t substdio_get(substdio *s, char *buf, size_t len) if (s->p > 0) return getthis(s,buf,len); if (s->n <= len) return oneread(s->op,s->fd,buf,len); - r = substdio_feed(s); if (r <= 0) return r; + r = substdio_feed(s); + if (r == 0 || r == -1) return r; return getthis(s,buf,len); } diff --git a/tcpto.c b/tcpto.c @@ -25,7 +25,7 @@ static int getbuf() if (lock_ex(fdlock) == -1) { close(fdlock); close(fd); return 0; } r = read(fd,tcpto_buf,sizeof(tcpto_buf)); close(fd); - if (r < 0) { close(fdlock); return 0; } + if (r == -1) { close(fdlock); return 0; } r >>= 4; if (!r) close(fdlock); return r;