Skip to content

Commit 2d743af

Browse files
committed
[msan] Unpoison trailing nullptr in wordexp interceptor
Differential Revision: https://reviews.llvm.org/D108665
1 parent 4c699b1 commit 2d743af

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

compiler-rt/lib/msan/tests/msan_test.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3750,6 +3750,14 @@ TEST(MemorySanitizer, getgroups_negative) {
37503750
ASSERT_EQ(-1, n);
37513751
}
37523752

3753+
TEST(MemorySanitizer, wordexp_empty) {
3754+
wordexp_t w;
3755+
int res = wordexp("", &w, 0);
3756+
ASSERT_EQ(0, res);
3757+
ASSERT_EQ(0U, w.we_wordc);
3758+
ASSERT_STREQ(nullptr, w.we_wordv[0]);
3759+
}
3760+
37533761
TEST(MemorySanitizer, wordexp) {
37543762
wordexp_t w;
37553763
int res = wordexp("a b c", &w, 0);

compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3998,9 +3998,8 @@ INTERCEPTOR(int, wordexp, char *s, __sanitizer_wordexp_t *p, int flags) {
39983998
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, p, sizeof(*p));
39993999
uptr we_wordc =
40004000
((flags & wordexp_wrde_dooffs) ? p->we_offs : 0) + p->we_wordc;
4001-
if (we_wordc)
4002-
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, p->we_wordv,
4003-
sizeof(*p->we_wordv) * we_wordc);
4001+
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, p->we_wordv,
4002+
sizeof(*p->we_wordv) * (we_wordc + 1));
40044003
for (uptr i = 0; i < we_wordc; ++i) {
40054004
char *w = p->we_wordv[i];
40064005
if (w) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, w, internal_strlen(w) + 1);

0 commit comments

Comments
 (0)