summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org>2019-01-25 12:34:13 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2019-01-25 12:34:13 (GMT)
commitbc4d023a3810a7da6ede2cc522cdc34fa3129378 (patch) (side-by-side diff)
treef8c79ba0ab5440a13ab59fbb7862c1f119a41ea6
parent2d47b2e12416e8c48673fd5fb60717ef3963abf7 (diff)
downloadmailutils-bc4d023a3810a7da6ede2cc522cdc34fa3129378.tar.gz
mailutils-bc4d023a3810a7da6ede2cc522cdc34fa3129378.tar.bz2
Improve error checking in stream writing functions.
* libmailutils/stream/stream.c (mu_stream_write): Return EIO on short writes if pnwritten is NULL. * libmailutils/stream/streamcpy.c (mu_stream_copy): Likewise (if source stream size is known.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libmailutils/stream/stream.c5
-rw-r--r--libmailutils/stream/streamcpy.c43
2 files changed, 27 insertions, 21 deletions
diff --git a/libmailutils/stream/stream.c b/libmailutils/stream/stream.c
index de995aa..8c9cbb6 100644
--- a/libmailutils/stream/stream.c
+++ b/libmailutils/stream/stream.c
@@ -1030,6 +1030,11 @@ mu_stream_write (mu_stream_t stream, const void *buf, size_t size,
}
if (pnwritten)
*pnwritten = nbytes;
+ else if (nbytes < size)
+ {
+ rc = EIO;
+ mu_stream_seterr (stream, rc, 1);
+ }
}
return rc;
}
diff --git a/libmailutils/stream/streamcpy.c b/libmailutils/stream/streamcpy.c
index 3270ee9..aaf0e72 100644
--- a/libmailutils/stream/streamcpy.c
+++ b/libmailutils/stream/streamcpy.c
@@ -38,7 +38,7 @@ mu_stream_copy (mu_stream_t dst, mu_stream_t src, mu_off_t size,
size_t bufsize, n;
char *buf;
mu_off_t total = 0;
-
+
if (pcsz)
*pcsz = 0;
if (size == 0)
@@ -56,7 +56,7 @@ mu_stream_copy (mu_stream_t dst, mu_stream_t src, mu_off_t size,
default:
return status;
}
-
+
if (size)
{
mu_off_t pos;
@@ -68,7 +68,7 @@ mu_stream_copy (mu_stream_t dst, mu_stream_t src, mu_off_t size,
return ESPIPE;
size -= pos;
break;
-
+
case EACCES:
mu_stream_clearerr (src);
case ENOSYS:
@@ -90,21 +90,26 @@ mu_stream_copy (mu_stream_t dst, mu_stream_t src, mu_off_t size,
return ENOMEM;
if (size)
- while (size)
- {
- size_t rdsize = bufsize < size ? bufsize : size;
+ {
+ while (size)
+ {
+ size_t rdsize = bufsize < size ? bufsize : size;
- status = mu_stream_read (src, buf, rdsize, &n);
- if (status)
- break;
- if (n == 0)
- break;
- status = mu_stream_write (dst, buf, n, NULL);
- if (status)
- break;
- size -= n;
- total += n;
- }
+ status = mu_stream_read (src, buf, rdsize, &n);
+ if (status)
+ break;
+ if (n == 0)
+ break;
+ status = mu_stream_write (dst, buf, n, NULL);
+ if (status)
+ break;
+ size -= n;
+ total += n;
+ }
+
+ if (!pcsz && size)
+ status = EIO;
+ }
else
while ((status = mu_stream_read (src, buf, bufsize, &n)) == 0
&& n > 0)
@@ -124,7 +129,3 @@ mu_stream_copy (mu_stream_t dst, mu_stream_t src, mu_off_t size,
free (buf);
return status;
}
-
-
-
-

Return to:

Send suggestions and report system problems to the System administrator.