Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/crypto/nist_hash_drbg Use CTASSERT where possible, run-t...



details:   https://anonhg.NetBSD.org/src/rev/6dd9c5de9fed
branches:  trunk
changeset: 965496:6dd9c5de9fed
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Thu Sep 19 14:34:59 2019 +0000

description:
Use CTASSERT where possible, run-time assertion where not.

Should fix negative-length variable-length array found by kamil.

diffstat:

 sys/crypto/nist_hash_drbg/nist_hash_drbg.c |  8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diffs (29 lines):

diff -r c2e5e17dc6fd -r 6dd9c5de9fed sys/crypto/nist_hash_drbg/nist_hash_drbg.c
--- a/sys/crypto/nist_hash_drbg/nist_hash_drbg.c        Thu Sep 19 11:31:57 2019 +0000
+++ b/sys/crypto/nist_hash_drbg/nist_hash_drbg.c        Thu Sep 19 14:34:59 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nist_hash_drbg.c,v 1.1 2019/09/02 20:09:29 riastradh Exp $     */
+/*     $NetBSD: nist_hash_drbg.c,v 1.2 2019/09/19 14:34:59 riastradh Exp $     */
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -49,7 +49,7 @@
 
 #ifdef _KERNEL
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nist_hash_drbg.c,v 1.1 2019/09/02 20:09:29 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nist_hash_drbg.c,v 1.2 2019/09/19 14:34:59 riastradh Exp $");
 #endif
 
 #include <sys/param.h>
@@ -1009,6 +1009,10 @@
 #define        CHECK(i, name, actual, expected, n) do                                \
 {                                                                            \
        CTASSERT(sizeof(actual) == (n));                                      \
+       CTASSERT(__builtin_constant_p(n) ? sizeof(actual) == (n) : 1);        \
+       ASSERT(__builtin_constant_p(n) ? 1 : sizeof(actual) >= (n));          \
+       CTASSERT(__builtin_constant_p(n) ? sizeof(expected) == (n) : 1);      \
+       ASSERT(__builtin_constant_p(n) ? 1 : sizeof(expected) >= (n));        \
        ok &= check(i, name, actual, expected, (n));                          \
 } while (0)
 



Home | Main Index | Thread Index | Old Index