Skip to content

Commit d970f49

Browse files
committed
Check the channel packet overhead literal against its expression
CHANNEL_PACKET_OVERHEAD_MAX is a hand-computed copy of CHANNEL_PACKET_OVERHEAD_SZ, needed because the expression bottoms out in wolfCrypt enum constants that #if reads as zero. Nothing tied the two together, so a term added to the expression would leave the #error guarding DEFAULT_MAX_PACKET_SZ silently ineffective. Assert the bound in internal.c, where both are ordinary constant expressions, with a negative-array-size typedef.
1 parent bbd4d0c commit d970f49

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

src/internal.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,17 @@
9898

9999
#include <wolfssl/wolfcrypt/coding.h>
100100

101+
102+
/* CHANNEL_PACKET_OVERHEAD_MAX is the preprocessor's stand-in for
103+
* CHANNEL_PACKET_OVERHEAD_SZ, whose terms bottom out in wolfCrypt enum
104+
* constants that #if reads as zero. The #error in internal.h therefore
105+
* cannot compare the two. Here both are ordinary constant expressions, so
106+
* a term added to the expression without bumping the literal fails the
107+
* build instead of quietly leaving DEFAULT_MAX_PACKET_SZ unguarded. */
108+
typedef char wolfSSH_channel_overhead_check[
109+
(CHANNEL_PACKET_OVERHEAD_SZ <= CHANNEL_PACKET_OVERHEAD_MAX) ? 1 : -1];
110+
111+
101112
/*
102113
Flags:
103114
HAVE_WC_ECC_SET_RNG

0 commit comments

Comments
 (0)