[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 08/55: Fix list validation of *list->bytevector procedur
From: |
Andy Wingo |
Subject: |
[Guile-commits] 08/55: Fix list validation of *list->bytevector procedures. |
Date: |
Thu, 23 May 2019 11:52:37 -0400 (EDT) |
wingo pushed a commit to branch master
in repository guile.
commit 5dcad70d993e68b0b175efff8c9b3b7477a74891
Author: Mark H Weaver <address@hidden>
Date: Sun Oct 14 02:22:22 2018 -0400
Fix list validation of *list->bytevector procedures.
Fixes <https://bugs.gnu.org/32938>.
Reported by Josh Datko <address@hidden>.
* libguile/validate.h (SCM_VALIDATE_LIST_COPYLEN)
(SCM_VALIDATE_NONEMPTYLIST_COPYLEN): Use '!=' instead of '>=' to
validate the result of 'scm_ilength' after it has been stored in
the user variable 'cvar'.
* test-suite/tests/bytevectors.test: Add tests. Use '#:use-module'
instead of ':use-module' in 'define-module' form.
---
libguile/list.h | 10 +++++++---
test-suite/tests/bytevectors.test | 37 ++++++++++++++++++++++++++++++++-----
2 files changed, 39 insertions(+), 8 deletions(-)
diff --git a/libguile/list.h b/libguile/list.h
index a494a48..5ebcc8a 100644
--- a/libguile/list.h
+++ b/libguile/list.h
@@ -1,7 +1,7 @@
#ifndef SCM_LIST_H
#define SCM_LIST_H
-/* Copyright 1995-1997,2000-2001,2003-2006,2008-2009,2018
+/* Copyright 1995-1997,2000-2001,2003-2006,2008-2009,2018-2019
Free Software Foundation, Inc.
This file is part of Guile.
@@ -88,16 +88,20 @@ SCM_API SCM scm_copy_tree (SCM obj);
SCM_ASSERT (scm_ilength (lst) > 0, lst, pos, FUNC_NAME); \
} while (0)
+/* Note: we use (cvar != -1) instead of (cvar >= 0) below
+ in case 'cvar' is of unsigned type. */
#define SCM_VALIDATE_LIST_COPYLEN(pos, lst, cvar) \
do { \
cvar = scm_ilength (lst); \
- SCM_ASSERT (cvar >= 0, lst, pos, FUNC_NAME); \
+ SCM_ASSERT (cvar != -1, lst, pos, FUNC_NAME); \
} while (0)
+/* Note: we use (cvar != -1) instead of (cvar >= 0) below
+ in case 'cvar' is of unsigned type. */
#define SCM_VALIDATE_NONEMPTYLIST_COPYLEN(pos, lst, cvar) \
do { \
cvar = scm_ilength (lst); \
- SCM_ASSERT (cvar >= 1, lst, pos, FUNC_NAME); \
+ SCM_ASSERT (cvar != -1, lst, pos, FUNC_NAME); \
} while (0)
diff --git a/test-suite/tests/bytevectors.test
b/test-suite/tests/bytevectors.test
index f0d9f19..5d4568d 100644
--- a/test-suite/tests/bytevectors.test
+++ b/test-suite/tests/bytevectors.test
@@ -1,6 +1,6 @@
;;;; bytevectors.test --- R6RS bytevectors. -*- mode: scheme; coding: utf-8;
-*-
;;;;
-;;;; Copyright (C) 2009-2015 Free Software Foundation, Inc.
+;;;; Copyright (C) 2009-2015, 2018 Free Software Foundation, Inc.
;;;;
;;;; Ludovic Courtès
;;;;
@@ -19,10 +19,11 @@
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
(define-module (test-bytevector)
- :use-module (test-suite lib)
- :use-module (system base compile)
- :use-module (rnrs bytevectors)
- :use-module (srfi srfi-4))
+ #:use-module (test-suite lib)
+ #:use-module (system base compile)
+ #:use-module (rnrs bytevectors)
+ #:use-module (srfi srfi-1)
+ #:use-module (srfi srfi-4))
(define exception:decoding-error
(cons 'decoding-error "input (locale conversion|decoding) error"))
@@ -111,6 +112,14 @@
(equal? lst
(bytevector->u8-list (u8-list->bytevector lst)))))
+ (pass-if-exception "u8-list->bytevector [invalid argument type]"
+ exception:wrong-type-arg
+ (u8-list->bytevector 'not-a-list))
+
+ (pass-if-exception "u8-list->bytevector [circular list]"
+ exception:wrong-type-arg
+ (u8-list->bytevector (circular-list 1 2 3)))
+
(pass-if "bytevector-uint-{ref,set!} [small]"
(let ((b (make-bytevector 15)))
(bytevector-uint-set! b 0 #x1234
@@ -206,6 +215,24 @@
(bytevector-u8-set! bv 3 #xff)
bv)))
+ (pass-if-exception "sint-list->bytevector [invalid argument type]"
+ exception:wrong-type-arg
+ (sint-list->bytevector 'not-a-list (endianness big) 2))
+
+ (pass-if-exception "uint-list->bytevector [invalid argument type]"
+ exception:wrong-type-arg
+ (uint-list->bytevector 'not-a-list (endianness big) 2))
+
+ (pass-if-exception "sint-list->bytevector [circular list]"
+ exception:wrong-type-arg
+ (sint-list->bytevector (circular-list 1 2 3) (endianness big)
+ 2))
+
+ (pass-if-exception "uint-list->bytevector [circular list]"
+ exception:wrong-type-arg
+ (uint-list->bytevector (circular-list 1 2 3) (endianness big)
+ 2))
+
(pass-if-exception "sint-list->bytevector [out-of-range]"
exception:out-of-range
(sint-list->bytevector (list 0 0 (expt 2 16)) (endianness big)
- [Guile-commits] 24/55: SRFI-19: time-utc->date: Support non-integer nanoseconds values., (continued)
- [Guile-commits] 24/55: SRFI-19: time-utc->date: Support non-integer nanoseconds values., Andy Wingo, 2019/05/23
- [Guile-commits] 21/55: SRFI-19: Add a few more tests., Andy Wingo, 2019/05/23
- [Guile-commits] 11/55: In 'ash' and 'round-ash', handle right shift count of LONG_MIN., Andy Wingo, 2019/05/23
- [Guile-commits] 16/55: Add tests for type inferencing for 'nil?' and 'null?' predicates., Andy Wingo, 2019/05/23
- [Guile-commits] 22/55: SRFI-19: Fix normalization of seconds and nanoseconds in time records., Andy Wingo, 2019/05/23
- [Guile-commits] 20/55: SRFI-19: Fix handling of negative years and negative julian days., Andy Wingo, 2019/05/23
- [Guile-commits] 37/55: Avoid leaking a file descriptor in test-unwind, Andy Wingo, 2019/05/23
- [Guile-commits] 38/55: Fix binary output on files created by mkstemp!, Andy Wingo, 2019/05/23
- [Guile-commits] 43/55: Fix typo in comment., Andy Wingo, 2019/05/23
- [Guile-commits] 04/55: Define AT_SYMLINK_NOFOLLOW et al., Andy Wingo, 2019/05/23
- [Guile-commits] 08/55: Fix list validation of *list->bytevector procedures.,
Andy Wingo <=
- [Guile-commits] 13/55: Update SRFI-19 leap second table., Andy Wingo, 2019/05/23
- [Guile-commits] 05/55: Fix 'atomic-box-compare-and-swap!'., Andy Wingo, 2019/05/23
- [Guile-commits] 26/55: Add texinfo dependency to README, Andy Wingo, 2019/05/23
- [Guile-commits] 27/55: Bootstrap optimization, Andy Wingo, 2019/05/23
- [Guile-commits] 32/55: Fix tests for SRFI-19 date->string ~N, Andy Wingo, 2019/05/23
- [Guile-commits] 33/55: Do not warn the user when 'madvise' returns ENOSYS., Andy Wingo, 2019/05/23
- [Guile-commits] 30/55: Update (ice-9 match) to include selected bug fixes from upstream., Andy Wingo, 2019/05/23
- [Guile-commits] 31/55: Support ~N in SRFI-19 string->date, Andy Wingo, 2019/05/23
- [Guile-commits] 28/55: Documentation fixes, Andy Wingo, 2019/05/23
- [Guile-commits] 42/55: Disable test for current value of setitimer on Cygwin, Andy Wingo, 2019/05/23