[msan] Unpoison trailing nullptr in wordexp interceptor

Differential Revision: https://reviews.llvm.org/D108665
This commit is contained in:
Vitaly Buka 2021-08-24 14:43:59 -07:00
parent 4c699b1cd0
commit 2d743af4e9
2 changed files with 10 additions and 3 deletions

View File

@ -3750,6 +3750,14 @@ TEST(MemorySanitizer, getgroups_negative) {
ASSERT_EQ(-1, n);
}
TEST(MemorySanitizer, wordexp_empty) {
wordexp_t w;
int res = wordexp("", &w, 0);
ASSERT_EQ(0, res);
ASSERT_EQ(0U, w.we_wordc);
ASSERT_STREQ(nullptr, w.we_wordv[0]);
}
TEST(MemorySanitizer, wordexp) {
wordexp_t w;
int res = wordexp("a b c", &w, 0);

View File

@ -3998,9 +3998,8 @@ INTERCEPTOR(int, wordexp, char *s, __sanitizer_wordexp_t *p, int flags) {
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, p, sizeof(*p));
uptr we_wordc =
((flags & wordexp_wrde_dooffs) ? p->we_offs : 0) + p->we_wordc;
if (we_wordc)
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, p->we_wordv,
sizeof(*p->we_wordv) * we_wordc);
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, p->we_wordv,
sizeof(*p->we_wordv) * (we_wordc + 1));
for (uptr i = 0; i < we_wordc; ++i) {
char *w = p->we_wordv[i];
if (w) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, w, internal_strlen(w) + 1);