summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjulien.pierre.boogz%sun.com <devnull@localhost>2007-08-29 01:30:07 +0000
committerjulien.pierre.boogz%sun.com <devnull@localhost>2007-08-29 01:30:07 +0000
commit775e03ad29c1e75d149eb876e843a887690026d1 (patch)
tree721cf4467b365439a34972b3dbddf810c83aee1a
parent35cd117c3502fdb97f1ab152a20fd2b29fd4dccc (diff)
downloadnspr-hg-775e03ad29c1e75d149eb876e843a887690026d1.tar.gz
Fix for bug 369036. Prevent infinite loop in pt_SolarisSendFile. r=wtchang, nelson
-rw-r--r--pr/src/md/unix/unix_errors.c16
-rw-r--r--pr/src/pthreads/ptio.c17
2 files changed, 32 insertions, 1 deletions
diff --git a/pr/src/md/unix/unix_errors.c b/pr/src/md/unix/unix_errors.c
index 4fbcd821..90ebe7de 100644
--- a/pr/src/md/unix/unix_errors.c
+++ b/pr/src/md/unix/unix_errors.c
@@ -851,7 +851,21 @@ void _MD_hpux_map_sendfile_error(int err)
#ifdef SOLARIS
void _MD_solaris_map_sendfile_error(int err)
{
- _MD_unix_map_default_error(err) ;
+ PRErrorCode prError;
+
+ switch (err) {
+ /*
+ * Solaris defines a 0 return value for sendfile to mean end-of-file.
+ */
+ case 0:
+ prError = PR_END_OF_FILE_ERROR;
+ break;
+
+ default:
+ _MD_unix_map_default_error(err) ;
+ return;
+ }
+ PR_SetError(prError, err);
}
#endif /* SOLARIS */
diff --git a/pr/src/pthreads/ptio.c b/pr/src/pthreads/ptio.c
index aacc8d6f..09f9942e 100644
--- a/pr/src/pthreads/ptio.c
+++ b/pr/src/pthreads/ptio.c
@@ -1072,6 +1072,15 @@ static PRBool pt_solaris_sendfile_cont(pt_Continuation *op, PRInt16 revents)
return PR_TRUE;
}
count = xferred;
+ } else if (count == 0) {
+ /*
+ * We are now at EOF. The file was truncated. Solaris sendfile is
+ * supposed to return 0 and no error in this case, though some versions
+ * may return -1 and EINVAL .
+ */
+ op->result.code = -1;
+ op->syserrno = 0; /* will be treated as EOF */
+ return PR_TRUE;
}
PR_ASSERT(count <= op->nbytes_to_send);
@@ -2420,6 +2429,14 @@ static PRInt32 pt_SolarisSendFile(PRFileDesc *sd, PRSendFileData *sfd,
|| syserrno == EAGAIN || syserrno == EWOULDBLOCK) {
count = xferred;
}
+ } else if (count == 0) {
+ /*
+ * We are now at EOF. The file was truncated. Solaris sendfile is
+ * supposed to return 0 and no error in this case, though some versions
+ * may return -1 and EINVAL .
+ */
+ count = -1;
+ syserrno = 0; /* will be treated as EOF */
}
if (count != -1 && count < nbytes_to_send) {