[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 01/02: Fix range checking in new Scheme-to-C port code
From: |
Andy Wingo |
Subject: |
[Guile-commits] 01/02: Fix range checking in new Scheme-to-C port code |
Date: |
Sun, 22 May 2016 21:04:03 +0000 (UTC) |
wingo pushed a commit to branch master
in repository guile.
commit 4e288ec2ff9c5387951dcb7f78f3193261228878
Author: Andy Wingo <address@hidden>
Date: Sun May 22 22:33:46 2016 +0200
Fix range checking in new Scheme-to-C port code
* libguile/ports.c (trampoline_to_c_read, trampoline_to_c_write): Fix
bugs checking ranges of start and count parameters.
---
libguile/ports.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/libguile/ports.c b/libguile/ports.c
index 445ccc0..ff1db9d 100644
--- a/libguile/ports.c
+++ b/libguile/ports.c
@@ -172,10 +172,11 @@ trampoline_to_c_read (SCM port, SCM dst, SCM start, SCM
count)
size_t c_start, c_count, ret;
SCM_VALIDATE_OPPORT (1, port);
+ SCM_VALIDATE_BYTEVECTOR (2, dst);
c_start = scm_to_size_t (start);
c_count = scm_to_size_t (count);
- SCM_ASSERT_RANGE (2, start, c_start <= c_count);
- SCM_ASSERT_RANGE (3, count, c_start+c_count <= scm_c_bytevector_length
(dst));
+ SCM_ASSERT_RANGE (3, start, c_start <= SCM_BYTEVECTOR_LENGTH (dst));
+ SCM_ASSERT_RANGE (4, count, c_count <= SCM_BYTEVECTOR_LENGTH (dst) -
c_start);
ret = SCM_PORT_TYPE (port)->c_read (port, dst, c_start, c_count);
@@ -198,10 +199,11 @@ trampoline_to_c_write (SCM port, SCM src, SCM start, SCM
count)
size_t c_start, c_count, ret;
SCM_VALIDATE_OPPORT (1, port);
+ SCM_VALIDATE_BYTEVECTOR (2, src);
c_start = scm_to_size_t (start);
c_count = scm_to_size_t (count);
- SCM_ASSERT_RANGE (2, start, c_start <= c_count);
- SCM_ASSERT_RANGE (3, count, c_start+c_count <= scm_c_bytevector_length
(src));
+ SCM_ASSERT_RANGE (3, start, c_start <= SCM_BYTEVECTOR_LENGTH (src));
+ SCM_ASSERT_RANGE (4, count, c_count <= SCM_BYTEVECTOR_LENGTH (src) -
c_start);
ret = SCM_PORT_TYPE (port)->c_write (port, src, c_start, c_count);