Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1e2a445

Browse files
committed
use __bounds check
__attribute__((__element_count__(siz))). See https://people.kernel.org/kees/bounded-flexible-arrays-in-c
1 parent 71f4a91 commit 1e2a445

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

‎core/potion.h‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ and optionally args, statically typed via signature strings.
6666
#else
6767
# define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS
6868
#endif
69+
70+
#if HAVE_ATTRIBUTE_ELEMENT_COUNT
71+
# define __bounds(siz) __attribute__((__element_count__(siz)))
72+
#else
73+
# define __bounds(siz)
74+
#endif
75+
6976
#ifdef DEBUG
7077
# ifndef YY_DEBUG
7178
# define YY_DEBUG
@@ -226,7 +233,7 @@ typedef _PN (*PN_F)(Potion *, PN, PN, ...);
226233
PNType vt; \
227234
PNUniq uniq
228235

229-
#define PN_FLEX(N, T) typedef struct { PN_OBJECT_HEADER; PN_SIZE len; PN_SIZE siz; T ptr[]; } N
236+
#define PN_FLEX(N, T) typedef struct { PN_OBJECT_HEADER; PN_SIZE len; PN_SIZE siz; T ptr[] __bounds(siz); } N
230237
#define PN_FLEX_AT(N, I) ((PNFlex *)(N))->ptr[I]
231238
#define PN_FLEX_SIZE(N) ((PNFlex *)(N))->len
232239

‎tools/config.sh‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,10 @@ else
161161
STACKDIR=`echo "#include <stdlib.h>#include <stdio.h>void a2(int *a, int b, int c) { printf(\\"%d\\", (int)((&b - a) / abs(&b - a))); }void a1(int a) { a2(&a,a+4,a+2); }int main() { a1(9); return 0; }" > $AC && $CCEX && $AOUT && rm -f $AOUT`
162162
fi
163163
#ARGDIR=`echo "#include <stdio.h>void a2(int *a, int b, int c) { printf(\\"%d\\", (int)(&c - &b)); }void a1(int a) { a2(&a,a+4,a+2); }int main() { a1(9); return 0; }" > $AC && $CCEX && $AOUT && rm -f $AOUT`
164-
HAVE_ASAN=`echo "#include <stdio.h>__attribute__((no_address_safety_analysis)) int main() { puts(\\"1\\"); return 0; }" > $AC && $CCEX -Werror 3ドル 2>&1 && $AOUT && rm -f $AOUT`
164+
HAVE_ASAN=`echo "#include <stdio.h>__attribute__((no_address_safety_analysis)) int main() { puts(\\"1\\"); return 0; }" > $AC && $CCEX -Werror 3ドル 2>&1 && $AOUT && rm -f $AOUT`
165165
if [ "$HAVE_ASAN" = "1" ]; then HAVE_ASAN=1; else HAVE_ASAN=0; fi
166+
HAVE_ATTRIBUTE_ELEMENT_COUNT=`echo "#include <stdio.h>struct{int size;int flex[] __attribute__((__element_count__(siz)));}x;int main() { puts(\\"1\\"); return 0; }" > $AC && $CCEX -Werror 3ドル 2>&1 && $AOUT && rm -f $AOUT`
167+
if [ "$HAVE_ATTRIBUTE_ELEMENT_COUNT" = "1" ]; then HAVE_ATTRIBUTE_ELEMENT_COUNT=1; else HAVE_ATTRIBUTE_ELEMENT_COUNT=0; fi
166168
else
167169
# hard coded win32 values
168170
if [ "$JIT_X86_64" != "" -o "$JIT_AMD64" != "" ]; then
@@ -186,6 +188,7 @@ else
186188
fi
187189
STACKDIR="-1"
188190
HAVE_ASAN="0"
191+
HAVE_ATTRIBUTE_ELEMENT_COUNT="0"
189192
fi
190193

191194
echo "#define POTION_PLATFORM \"$TARGET\""
@@ -203,6 +206,7 @@ else
203206
echo "#define POTION_STACK_DIR $STACKDIR"
204207
#echo "#define POTION_ARGS_DIR $ARGDIR"
205208
echo "#define HAVE_ASAN_ATTR $HAVE_ASAN"
209+
echo "#define HAVE_ATTRIBUTE_ELEMENT_COUNT $HAVE_ATTRIBUTE_ELEMENT_COUNT"
206210
echo "#ifndef SANDBOX"
207211
echo "#define WITH_EXTERN 1"
208212
echo "#endif"

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /