summaryrefslogtreecommitdiffstats
path: root/ssl
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2014-05-11 11:27:26 +0100
committerMatt Caswell <matt@openssl.org>2014-05-11 11:32:17 +0100
commitf2ebe2a60eacf3e348898175be82971b57d72327 (patch)
tree3875963339f8e1221e1b53197f96a8e05634f8b4 /ssl
parent011ee91105f00cb2465110ce6431b11b51556d08 (diff)
Move length check earlier to ensure we don't go beyond the end of the user's buffer. PR#3320
Diffstat (limited to 'ssl')
-rw-r--r--ssl/s3_pkt.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/ssl/s3_pkt.c b/ssl/s3_pkt.c
index 0d3f47780a..8a23de5f34 100644
--- a/ssl/s3_pkt.c
+++ b/ssl/s3_pkt.c
@@ -619,6 +619,21 @@ int ssl3_write_bytes(SSL *s, int type, const void *buf_, int len)
}
}
+ /* ensure that if we end up with a smaller value of data to write
+ * out than the the original len from a write which didn't complete
+ * for non-blocking I/O and also somehow ended up avoiding
+ * the check for this in ssl3_write_pending/SSL_R_BAD_WRITE_RETRY as
+ * it must never be possible to end up with (len-tot) as a large
+ * number that will then promptly send beyond the end of the users
+ * buffer ... so we trap and report the error in a way the user
+ * will notice
+ */
+ if ( len < tot)
+ {
+ SSLerr(SSL_F_SSL3_WRITE_BYTES,SSL_R_BAD_LENGTH);
+ return(-1);
+ }
+
/* first check if there is a SSL3_BUFFER still being written
* out. This will happen with non blocking IO */
if (wb->left != 0)
@@ -777,20 +792,6 @@ int ssl3_write_bytes(SSL *s, int type, const void *buf_, int len)
return tot;
}
- /* ensure that if we end up with a smaller value of data to write
- * out than the the original len from a write which didn't complete
- * for non-blocking I/O and also somehow ended up avoiding
- * the check for this in ssl3_write_pending/SSL_R_BAD_WRITE_RETRY as
- * it must never be possible to end up with (len-tot) as a large
- * number that will then promptly send beyond the end of the users
- * buffer ... so we trap and report the error in a way the user
- * will notice
- */
- if ( len < tot)
- {
- SSLerr(SSL_F_SSL3_WRITE_BYTES,SSL_R_BAD_LENGTH);
- return(-1);
- }
n=(len-tot);
for (;;)