Skip to content

Commit d07d049

Browse files
fix(ci): MachO test buffer overflow + ClockTick on MSVC
Two failures surfaced when the previously-unpushed history reached the mirror CI for the first time: - Tests/Std/MachO.c: test_mh1_tab_end_addition sized its scaffold buffer u8 b[0x200] (512) but the layout's BUF reaches 544 (stroff 512 + strsize + slack), so b[stroff] and the trailing MemCopy ran one region past the array -- a UBSan/ASan out-of-bounds. Enlarge to 0x300. - ClockTick(): the GNU statement-expression + inline-asm form does not compile under real MSVC (cl.exe). Add an _MSC_VER (non-clang) branch using the __rdtsc() / _ReadStatusReg intrinsic; clang-cl keeps the GNU path.
1 parent 6bb5f90 commit d07d049

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

Include/Misra/Sys/Clock.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,16 @@
4242
///
4343
u64 ClockMonoNs(void);
4444

45-
#if ARCHITECTURE_X86_64
45+
#if defined(_MSC_VER) && !defined(__clang__)
46+
// Real MSVC (cl.exe) has no GNU statement-expressions / inline asm; use the
47+
// compiler intrinsic. clang-cl defines __clang__ and takes the GNU path below.
48+
# include <intrin.h>
49+
# if ARCHITECTURE_AARCH64
50+
# define ClockTick() ((u64)_ReadStatusReg(ARM64_CNTVCT))
51+
# else
52+
# define ClockTick() ((u64)__rdtsc())
53+
# endif
54+
#elif ARCHITECTURE_X86_64
4655
# define ClockTick() \
4756
(__extension__({ \
4857
u32 tsc_lo_, tsc_hi_; \

Tests/Std/MachO.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ bool test_mh1_tab_end_addition(void) {
822822
u32 stroff = symoff + tab_len; // strtab right after table
823823
u32 strsize = 16;
824824
u32 BUF = stroff + strsize + 16;
825-
u8 b[0x200];
825+
u8 b[0x300]; // must cover BUF (=544 here); 0x200 overflowed
826826
MemSet(b, 0, sizeof(b));
827827
SymCfg cfg = {.buf_size = BUF, .symoff = symoff, .nsyms = NSY, .stroff = stroff, .strsize = strsize};
828828
build_scaffold(b, &cfg);

0 commit comments

Comments
 (0)